import java.io.FileOutputStream;
public class Main{
public static void main(String[] args) throws Exception {
// 字节输出流 文件输出流,把数据写出到文件中
// 输出流构造方法的特点
FileOutputStream fo = new FileOutputStream("src\\zdd\\ywj02\\day06\\aaj.txt");
// FileOutputStream(File file):创建文件输出流,以写入由指定的 File对象表示的文件。
// FileOutputStream(String name): 创建文件输出流,以指定的名称写入文件。
// 如果没有该文件 将会创建 如果有将会覆盖
//FileOutputStream fo2 = new FileOutputStream("src\\zdd\\ywj02\\day06\\aaj.txt");
// 也可在之后追加: 写法 路径加,加true
//FileOutputStream fo3 = new FileOutputStream("src\\zdd\\ywj02\\day06\\aaj.txt",true);
// fo.write(97); // 写一个字节到 fo 关联的字节中 97 ASCII a
// 也可以连续给值
// byte[] arr = {97,98,99};
//fo.write(arr); 写数组中所有的数 // abc
//fo.write(arr,0,2);//写数组中 一部分元素 // [0,2) a b
//也可以写字符串到关联的文件中
//byte[] arr = "9798".getBytes();// 这就是字符串
//fo.write(arr);// "9798"
//fo.write("9798".getBytes() );// 写入9798
//fo.write("9798".getBytes(),0,3 );// [0,3) 979
//如果是中文的话则一个字 占三个字节
// fo.write("中国".getBytes() );// 写入中国
//fo.write("中国".getBytes(),0,2);// 写入 未知字符 错x
//fo.write("中国".getBytes(),0,3);// 只能写入 中 国 却不能写入
// fo.write("中国".getBytes(),0,5);// 只能写入 中 国 为未知
//fo.write("中国".getBytes(),0,6);//正确写法 一个字占三位 两字六位 写入:中国
fo.close();
}
}
FileOutputStream构造方法介绍字节输出流没有文件创建特点和写方法写一个字节写一个字节数组写一个字节数组的一部分
最新推荐文章于 2023-01-17 23:32:39 发布