在文件中数据的追加续写

package day31;

import java.io.FileOutputStream;
import java.io.IOException;

/*
public FileOutputStream(File file,boolean append)
1:创建一个向指定 File 对象表示的文件中写入数据的文件输出流。
用法:创建一个向具有指定 file的文件中写入数据的输出文件流。
如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。
2:public FileOutputStream(String name,boolean append)
创建一个向具有指定 name 的文件中写入数据的输出文件流。
用法:创建一个向具有指定 name 的文件中写入数据的输出文件流。
如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。
file ,name为写文件的目的地;
append指是否续写;

换行符:
windows: ;
linux: /n;
mac:/r;
*/
public class adddatefile {
public static void main(String[] args) throws IOException {
FileOutputStream fe=new FileOutputStream("E:\congce\out.txt",true);
String str="你好!";
byte[] bytes=str.getBytes();
fe.write(bytes);
fe.write(" ".getBytes());
fe.write(bytes);
fe.close();
}


}
原文地址:https://www.cnblogs.com/huaobin/p/13721468.html