Append or add some contents to the file : File Writer « File Input Output « Java

Append or add some contents to the file


public class Main {
  public static void main(String[] args) throws Exception{
    File file = new File("user.txt");

    FileWriter writer = new FileWriter(file, true);
    writer.write("username=java;password=secret" + System.getProperty("line.separator"));


Related examples in the same category

1.Demonstrate FileWriter.
2.Use FileWriter to write an array of strings to a file.
3.Using a Reader and a Writer, returns a String from an InputStream
4.Implementation of a fast Writer.