This tutorial shows you how to append Content into a file in java.
Append means to add something at the end. Similarly, the following java program adds new Content into a file. File in-built function append() is used to add new content at the end.
If you do not about the file system in java then click the link below.
Program to Append Content into a File in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //append content into a file import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FileAppend { public static void main(String[] args) throws IOException { File f = new File("javaCode.txt"); FileWriter fw = new FileWriter(f,true); //Create filewriter object fw.append("Welcome to Simple2Code\n"); //Append the Content fw.flush(); fw.close(); System.out.println("Check javaCode.txt.") } } |
Output:
Check javaCode.txt.
Open the file that will be created in the same directory after execution.
javaCode.txt
Welcome to Simple2Code.