|
Append File
The following example shows how to append text to an existing file.
|
package com.bethecoder.tutorials.io;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class AppendFileTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
//Open file writer for appending text
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\abc.txt", true));
writer.newLine();
writer.write("Hello World2");
writer.newLine();
writer.write("Hello World3");
writer.close();
System.out.println("Successfully appended to file");
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
| |
It gives the following output,
Successfully appended to file
|
|