The following example demonstrates using the filewriter method to append data to a file:
/*
author by w3cschool.cc
Main.java
*/import java.io.*;public class Main {
public static void main(String[] args) throws Exception {
try {
BufferedWriter out = new BufferedWriter
(new FileWriter("filename"));
out.write("aString1\n");
out.close();
out = new BufferedWriter(new FileWriter
("filename",true));
out.write("aString2");
out.close();
BufferedReader in = new BufferedReader
(new FileReader("filename"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
}
in.close();
catch (IOException e) {
System.out.println("exception occoured"+ e);
}
}}
The output result of running the above code is:
aString1 aString2
above It is a Java example - the content of appending data to a file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!