关于java:BufferedOutputStream

8次阅读

共计 657 个字符,预计需要花费 2 分钟才能阅读完成。

一、字节缓冲流

public class BufferedOutputStream
public class BufferedInputStream


缓冲流进步字节读取效率
构造函数

BufferedOutputStream(OutputStream out)
BufferedinputStream(inputStream in)

操作:

  • 构造方法创建对象:

    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("E:\\xx\\xx.txt"))

    读数据:

    bos.write("hello\r\n".getBytes());

    资源开释:

    bos.close();
    

  • 构造方法创建对象:

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(""E:\\xx\\xx.txt""));

    写数据: 办法一 字符

    int by;
    while((by=bis.read())!=-1){System.Out.print(char(by));
    }

    写数据: 办法二 字节数组

    Byte[] b = new Byte[1024];
    int len;
    while((len=bis.read(b))!=-1){System.out.Print(String(b,0,len));
    }

    资源开释:

    bis.close();


    案例:复制视频


    —– 采纳四种形式 —–

    根本字节流 / 字节缓冲流
    —> 对应
    一次读一个字节 / 一次读一个字节数组


计时:

1

2

3

4

正文完
 0