zoukankan      html  css  js  c++  java
  • 文件下载比较

    package demo2;

    import java.io.*;


    public class Stream{
        //一个字节一个字节的复制,耗时11736毫秒
        public static  void  fun() throws IOException {
            FileInputStream fis = new FileInputStream("C:\Users\intasect\Desktop\Koala.jpg");
            FileOutputStream fos = new FileOutputStream("C:\Users\intasect\Desktop\fz.jpg");
            int by = 0;
            while ((by=fis.read()) != -1) {
                fos.write(by);
            }
            fis.close();
            fos.close();
        }
        //1024字节数组复制 耗时21毫秒
        public  static void  fun1() throws IOException {
             FileInputStream fis = new FileInputStream("C:\Users\intasect\Desktop\Koala.jpg");
             FileOutputStream fos = new FileOutputStream("C:\Users\intasect\Desktop\fz.jpg");
            int len = 0;
            byte[] bytes =new byte[1024];
            while ((len=fis.read(bytes)) != -1) {
                fos.write(bytes,0,len);
            }
            fis.close();
            fos.close();
        }
        // 一个字节一个字节复制,但是用了缓冲流 耗时64毫秒
        public static   void  fun2() throws IOException {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\Users\intasect\Desktop\fz.jpg"));
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\Users\intasect\Desktop\Koala.jpg"));
            int by = 0;
            while ((by=bis.read()) != -1) {
                bos.write(by);
            }
            bis.close();
            bos.close();
        }
        // 1024字节数组复制并用了缓冲流 耗时7毫秒
        public  static void  fun3() throws IOException {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\Users\intasect\Desktop\fz.jpg"));
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\Users\intasect\Desktop\Koala.jpg"));
            int len = 0;
            byte[] bytes =new byte[1024];
            while ((len=bis.read(bytes)) != -1) {
                bos.write(bytes,0,len);
            }
            bis.close();
            bos.close();
        }

        public static void main(String args[]) throws IOException {
            long t1 = System.currentTimeMillis();
            fun3();
            long t2 = System.currentTimeMillis();
            System.out.println(t2-t1);
        }

    }

  • 相关阅读:
    Julia
    《风控策略笔记》之风控审批策略(三)--量化指标与策略调优
    《风控策略笔记》之风控审批策略(二)--决策引擎与策略调优
    《风控策略笔记》之风控审批策略(一)--前言与审批策略架构搭建和数据源
    schannel: next InitializeSecurityContext failed: SEC_E_ILLEGAL_MESSAGE错误
    从 kswapd0 进程CPU占用过高 到计算机内存详解
    pandas窗口函数--rolling
    请求行与相应行
    URI与URN与URL详解
    mysql索引详解
  • 原文地址:https://www.cnblogs.com/changefl/p/10766928.html
Copyright © 2011-2022 走看看