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();
        }
    
    }
    终身学习者
  • 相关阅读:
    学习计划 23月
    bash学习笔记
    bash 中 while读取文件并通过 ssh执行命令出现的问题及解决方法
    bash 学习笔记2
    fedora 启动 openssh
    lesson5 键盘的应用
    第十三章 int指令
    第十五章 外中断
    第十二章 内中断
    第十四章 端口
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/9946502.html
Copyright © 2011-2022 走看看