Hey it is very easy process to append data to a text file in java. You have to just use java.io and FileWriter class to do this. FileWriter class provides constructor that is used to accept a boolean parameter call append. In the following program you have to set boolean value true to append data to a text file.
Code:
package sample.code.java.io;
import java.io.*;
public class AppendFileEg
{
public static void main(String[] args)
{
File files = new File("sample.txt");
try
{
FileWriter writers = new FileWriter(files, true);
writer.write("usernames=omen;password=12345"
+ System.getProperty("line.separator"));
writers.flush();
writers.close();
} catch (IOException es)
{
es.printStackTrace();
}
}
}
Bookmarks