1. 以PrintWriter来实现写入
import java.io.*;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
String path="e://a.txt";
try {
FileWriter fw=new FileWriter(path,true);
PrintWriter pw=new PrintWriter(fw);
pw.println("世界");
pw.close();
//bw.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2. 以BufferedWriter来实现写入
[php]
import java.io.*;
public class test {
/** * @param args */
public static void main(String[] args) {
String path="e://a.txt";
try {
FileWriter fw=new FileWriter(path,true);
BufferedWriter bw=new BufferedWriter(fw);
bw.newLine();
bw.write("Hello");
bw.newLine();
bw.write("世界");
bw.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
[php]