FileWriter In Java Example
Chapter:
File
Last Updated:
18-07-2016 04:33:10 UTC
Program:
/* ............... START ............... */
import java.io.FileWriter;
import java.io.IOException;
public class JavaFileWriter {
public static void main(String args[]) throws IOException {
FileWriter fw = new FileWriter("out.txt");
for (int i = 0; i < 10; i++) {
fw.write("something");
}
fw.close();
}
}
/* ............... END ............... */
Notes:
-
Java FileWriter and FileReader classes are used to write and read data from text files.
- Syntax : FileWriter(String file) - creates a new file. It gets file name in string.
- FileWriter(File file) - creates a new file. It gets file name in File object.
Tags
FileWriter, Java