字节流写输入的三种方式

package com.czie.iot1913.lps01.IO.ioTest.OutputStream;

import java.io.FileOutputStream;
import java.io.IOException;

/**
* @author 1944900433@qq.com
* @date 2022-03-22 21:25
* void write(byte[] b)
* 写 b.length字节从指定的字节数组来此文件输出流。
* void write(byte[] b, int off, int len)
* 写 len字节指定字节数组中的起始偏移 off此文件输出流。
* void write(int b)
* 将指定的字节写入该文件输出流中。
*/
public class FileOutPutStreamDemo02 {
public static void main(String[] args) throws IOException {
FileOutputStream fos01 = new FileOutputStream("myList\\fos.txt");
//new File(name)
// File file = new File("myList\\fos.txt");
// FileOutputStream fos2 = new FileOutputStream(file);

// FileOutputStream fos2 = new FileOutputStream(new File("myList\\fos.txt"));
// * void write(int b)
// * 将指定的字节写入该文件输出流中。
// fos01.write(97);
// fos01.write(98);
// fos01.write('a');
// fos01.write('b');

//* void write(byte[] b)
// * 写 b.length字节从指定的字节数组来此文件输出流。
// byte [] bytes={97,98,99,'a'};
// fos01.write(bytes);
//String s="刘品水大帅锅";
//byte[] bytes = s.getBytes();
//fos01.write(bytes);

// * void write(byte[] b, int off, int len)
// * 写 len字节指定字节数组中的起始偏移 off此文件输出流。
String s1="abcdefghijk";
fos01.write(s1.getBytes(),1,5);

fos01.close();
//释放资源!!!
}
}

 

posted @   刘品水  阅读(100)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示