FileOutPutStream在创建对象的时候是如果没有这个文件会帮我创建出来
如果有这个文件,会清空掉内容在写入新的内容
package com.heima.inputstream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo2_FileOutInputstream {
public static void main(String[] args) throws IOException {
demo1();
FileOutputStream fos=new FileOutputStream("yyy.txt",true);//如果想续写的话,就在第二个参数传true
fos.write(101);
fos.close();
}
private static void demo1() throws FileNotFoundException, IOException {
FileOutputStream fos=new FileOutputStream("yyy.txt");//字节输出流,创建字节输出流对象,如果没有就自动创建一个
fos.write(97);
fos.write(98);
fos.write(99);
fos.close();
}
}