Writing to a text file in Java - BufferedWriter
In Java, textual data is edited and written with the BufferedWriter write stream. Unlike the BufferedInputStream data bit stream, you can directly write a string, char, or array to the .
https://docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html
Resources:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class ExampleBufferedWriter {
public static void main(String[] args) {
try {
String content = "This is the content added to the file";
File file = new File("test.txt");
// create the file if it doesn't exist
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Editing complete!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
https://docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html