Append to File in Java: Explanation & Practice
Append text to existing file
Problem summary
Append a new line to an existing file without overwriting.
Starter code
import java.io.*;
public class Main {
public static void main(String[] args) {
// Append "New line" to existing file
// Print: Append successful
}
}Expected output and test cases
- Line appended
Append successful
Hints
- FileWriter(file, true) for append mode
- Second boolean parameter enables append
- Don't forget newline character
Related File I/O exercises
Practice all File I/O exercises · Run this idea in the Java compiler