首页 > 其他分享 >字节流输出的使用步骤:

字节流输出的使用步骤:

时间:2022-10-06 12:44:27浏览次数:49  
标签:输出 字节 stream 步骤 写入 write file File

字节流输出的使用步骤:

  1. 创建一个FileOutPutStream对象,构造方法中传递写入数据的目的地。

  2. 调用FileOutPutStream对象中的方法write,把数据写入到文件中。

  3. 释放资源

     //创建一个File对象
     File file = new File("./a.txt");
     //创建一个文件
     file.createNewFile();
     //创建字节输出流
     FileOutputStream stream = new FileOutputStream(file);
     //写入97->a
     stream.write(97);
     //释放资源
     stream.close();
    

多个字节的写入方法:

  1. public void write(byte[] b); 将b.length字节从指定的字节数组写入此流中
  2. public void write(byte[] b, int off, int len); 从指定的字节数组写入len字节,从偏移量off开始输出到此流中

标签:输出,字节,stream,步骤,写入,write,file,File
From: https://www.cnblogs.com/-xyk/p/16757412.html

相关文章