- FileWriter provides a convenient way of writing characters to a file.
- FileWriter uses your computer's default character encoding.
public FileWriter (File file)
public FileWriter (File file, boolean append)
public FileWriter (String path)
public FileWriter (String path, boolean append)
public FileWriter (FileDescriptor fileDescriptor)
For example, you can construct a Writer that writes to a file easily using FileWriter:
import java.io.FileWriter;
import java.io.IOException;
public class MainClass {
public static void main(String[] a) {
FileWriter writer;
try {
writer = new FileWriter("myFile.txt");
char c = 'A';
writer.write(c);
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}