|
Write Text File
The following example shows how to write into a text file using BufferedWriter.
The newLine() method outputs a newline to the character stream.
|
package com.bethecoder.tutorials.io;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class WriteTextFile {
/**
* @param args
*/
public static void main(String[] args) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\abc.txt"));
writer.write("Hello World ");
writer.newLine();
writer.write("WriteTextFile Example");
writer.close();
System.out.println("Successfully written to file");
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
| |
It gives the following output,
Successfully written to file
|
|