Write String to a file with PrintWriter in Java

Description

The following code shows how to write String to a file with PrintWriter.

Example


  /* w  ww  . java  2s. c o  m*/

import java.io.IOException;
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) {
    try {
      PrintWriter pw = new PrintWriter("c:\\temp\\printWriterOutput.txt");
      pw.println("PrintWriter is easy to use.");
      pw.println(1234);
      pw.close();
    } catch (IOException e) {
    }
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip