【FileOutputStream类:write用法】

package test;

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

/**
 * @author shusheng
 * @description
 * @Email [email protected]
 * @date 2018/11/9 14:50
 */
public class FileOutputStreamDemo2 {

    public static void main(String[] args) throws IOException {
        /**
         *字节输出流操作步骤:
         *A:创建字节输出流对象
         *B:调用write()方法
         *C:释放资源
         *
         *public void write(int b):写一个字节
         *public void write(byte[] b):写一个字节数组
         *public void write(byte[] b,int off,int len):写一个字节数组的一部分
         */
        FileOutputStream fos = new FileOutputStream("fos.txt");
        byte[] bys = {97,98,99,100,101};
        fos.write('1');
        fos.write(bys);
        fos.write(bys, 0, 2);

        fos.close();
    }

}

猜你喜欢

转载自www.cnblogs.com/zuixinxian/p/9936006.html