java.io.FileWriter.FileWriter(String fileName, boolean append) throws IOException
FileWriter
public FileWriter(String fileName,
boolean append)
throws IOException
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
Parameters:
fileName - String The system-dependent filename.
append - boolean if true, then data will be written to the end of the file rather than the beginning.
Throws:
IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
实现的代码如下:
FileWriter fw = new FileWriter("e:\\ttp\\1.txt", true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("我爱java");
bw.newLine();
bw.flush(); //将数据更新至文件
bw.close();
fw.close();