字节输出流: OutputStream
自己的理解:首先先明确就是通过内存(电脑控制台)写入到文件当中,这样对于内存(电脑控制台)来说就是输出了.
public class TestOutputStream {
public static void main(String[] args) throws Exception {
// OutputStream 字节输出流 抽象类 可以自动创建文件 不会创建目录
File file = new File("d://abc/aaa.txt");
//创建目录
if(!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
OutputStream os = new FileOutputStream(file,false); // true:追加写入 false:覆盖写入
// 写
os.write(97); // 一次写入一个字节
//写一个字节数组
String str="我是你 爸爸";
os.write(str.getBytes()); // 写入一个字节数组
os.write(str.getBytes(), 0, 11);
//关闭流
os.close();
}
}