package demo5; import java.io.FileOutputStream; import java.io.IOException; /* * 追加写/续写:使用两个参数的构造方法 * FileOutputStream(String name,boolean append):创建一个向具有指定 name 的文件中写入数据的输出文件流 * FileOutputStream(File file,boolean append):创建一个向指定File对象表示的文件中写入数据的文件输出流 * 参数: * String name,File file:写入数据的目的地 * boolean append:追加写开关 * true:创建对象不会覆盖源文件,继续在文件的末尾追加写数据 * false:创建一个新文件,覆盖源文件 * 写换行:写换行符号 * Windows:\r\n * linux:/n * mac:/r * */ public class demo5 { public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("/Users/wanggang/Desktop/java/src/demo5/1.txt",true); fos.write("世界".getBytes()); fos.write("/n".getBytes()); fos.write("你好".getBytes()); fos.close(); } }
Java 基础 字节输出流的续写和换行
最新推荐文章于 2022-10-11 11:48:48 发布