用两个参数的那个重载函数。
public FileOutputStream(String name, boolean append)
throws FileNotFoundException创建一个向具有指定 name 的文件中写入数据的输出文件流。如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。创建一个新 FileDescriptor 对象来表示此文件连接。否则会把原来的文件清空。
public FileOutputStream(String name, boolean append)
throws FileNotFoundException创建一个向具有指定 name 的文件中写入数据的输出文件流。如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。创建一个新 FileDescriptor 对象来表示此文件连接。否则会把原来的文件清空。
import java.io.IOException;public class FileOut {
public static void main(String[] args) {
FileOutputStream fOut = null;
try{
fOut = new FileOutputStream("e:/a.txt", true);
} catch(IOException e) {
e.printStackTrace();
}
try {
fOut.write("abcdefg\r\n".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}