public class Number
{
public static void main(String[] args)
{
FileWriter fw = null;
try {
fw = new FileWriter("D://text.txt",true);
fw.write("dgldkfjgljjjjj");
fw.write("\r\n");
fw.write("11111");
fw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
}finally{
try {
if(fw!=null)
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
写入时,在原文件的结尾写入,初始化对象的时候加入一个参数true。如fw = new FileWriter("D://text.txt",true);
文件的写入的时候,要求换行,用.writer("\t\n");为什么用writer("\n”)不行? |
|