换行:
//创建字节输出流对象
//加参数true,就是追加写,不加就是重新写
FileOutputStream f=new FileOutputStream("2.txt",true);
for(int x=0;x<10;x++){
f.write(("hello"+x).getBytes());
f.write("\r\n".getBytes());//换行
}
//关闭流
f.close();
结果:
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9