- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4
Java Append to File with FileWriter
        Ramesh Fadatare edited this page Jul 12, 2019 
        ·
        1 revision
      
    FileWriter class is used for writing streams of characters. FileWriter takes an optional second parameter: append. If set to true, then the data will be written to the end of the file.
This example appends data to a file with FileWriter.
import java.io.FileWriter;
import java.io.IOException;
public class JavaAppendFileFileWriter {
    
    public static void main(String[] args) throws IOException {
        
        String fileName = "src/main/resources/sample.txt";
        
        try (FileWriter fw = new FileWriter(fileName, true)) {
            
            fw.append("Ramesh\n");
        }
    }
}