zoukankan      html  css  js  c++  java
  • 【字节缓冲流:实际实验结果】

    package test;
    
    import java.io.*;
    
    /**
     * @author shusheng
     * @description
     * @Email shusheng@yiji.com
     * @date 2018/11/12 9:21
     */
    public class BufferedOutputSteamDemo2 {
        /**
         * 为什么不传递一个具体的文件或者文件路径,而是传递一个OutputStream对象呢?
         * 原因很简单,字节缓冲区流仅仅提供缓冲区,为高效而设计的。但是呢,真正的读写操作还得靠基本的流对象实现
         * 实际实验结果:
         * 基本字节流一次读写一个字节: 共耗时:117235毫秒
         * 基本字节流一次读写一个字节数组: 共耗时:156毫秒
         * 高效字节流一次读写一个字节: 共耗时:1141毫秒
         * 高效字节流一次读写一个字节数组: 共耗时:47毫秒
         */
        public static void main(String[] args) throws IOException {
    
            BufferedInputStream bis = new BufferedInputStream(
                    new FileInputStream("C:\Users\shusheng\Pictures\111.txt"));
            BufferedOutputStream bos = new BufferedOutputStream(
                    new FileOutputStream("C:\Users\shusheng\Pictures\111.txt"));
            byte[] bys = new byte[1024];
            int len = 0;
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys);
            }
            bis.close();
            bos.close();
        }
    
    }
    终身学习者
  • 相关阅读:
    WPF 使用 Direct2D1 画图 绘制基本图形
    WPF 使用 Direct2D1 画图 绘制基本图形
    dot net core 使用 IPC 进程通信
    dot net core 使用 IPC 进程通信
    win2d 图片水印
    win2d 图片水印
    Java实现 LeetCode 240 搜索二维矩阵 II(二)
    PHP closedir() 函数
    PHP chroot() 函数
    PHP chdir() 函数
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/9946502.html
Copyright © 2011-2022 走看看