s-day09--文件的换行

This commit is contained in:
xx
2026-10-22 16:23:26 +08:00
parent 9a12cf27a3
commit a65374adac
+22
View File
@@ -0,0 +1,22 @@
package com.inmind.io01;
import java.io.FileOutputStream;
/* 文件的换行:
Windows:\r\n
linux:\n
mac:\r
注意:在同一次流操作中,不停地调用write方法,后面的数据是不会覆盖前面的数据的,之前是new了新流才会覆盖
*/
public class Demo05 {
public static void main(String[] args) throws Exception{
//创建一个覆写的字节输出流
FileOutputStream fos = new FileOutputStream("a.txt");
//输出换行的我是谁我在哪我在干嘛
// fos.write("我是谁\r\n我在哪\r\n我在干嘛".getBytes());
fos.write(("我是谁"+System.lineSeparator()
+"我在哪"+System.lineSeparator()+"我在干嘛").getBytes());
fos.close();
}
}