package day6;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamDemo02 {
public static void main(String[] args) throws IOException {
// FileOutputStream fos = new FileOutputStream("itheima\\day061.txt");
/* fos.write(97);
fos.write(98);
fos.write(99);
fos.write(100);
fos.write(101)*/;
/* byte[] byt = {97,98,99,100,101};
fos.write(byt);*/
/* byte[] byt = "爱你".getBytes();
fos.write(byt);
fos.write(byt,0,byt.length);
fos.close();*/
// 如何实现换行和追加写入?
// windows : \r\n
// linux: \n
// mac : \r
/*
* FileOutputStream fos = new FileOutputStream(String name,boolean append);
* */
FileOutputStream fos = new FileOutputStream("itheima\\day061.txt",true);
for (int i = 0; i < 10; i++) {
fos.write("爱你哟".getBytes());
fos.write("\r\n".getBytes());
}
fos.close();
}
}
|
|