zoukankan      html  css  js  c++  java
  • 第四次作业 文件复制速度的提升

    请教了很多才得出这个还算有效的方法,虽然不是我自己想出来的,但是我记住了,我觉得自己还是缺乏独立思维的能力所以才每次做作业都很吃力吧,希望会越来越有自己的思维。

    原代码为:

    package proj;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class Copy {
        public static void main(String []args){
            try {
                FileInputStream fis =new FileInputStream("a.mp3");
                FileOutputStream fos =new FileOutputStream("a.mp3");
                int read=fis.read();
                
               while(read !=-1){
                   fos.write(read);
                   read=fis.read();
                }
                fis.close();
                fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            long endTime = System.currentTimeMillis();
            long startTime = 0;
    		System.out.println("用时: " + (endTime - startTime) + " ms");
    
        }
    
    }
    

    修改的代码部分:

    byte[] buf = new byte[1024];
                int len = 0 ;//提高读取字节速度
                
                while((len=fis.read(buf)) != -1){
                fos.write(buf,0,len);}

     
  • 相关阅读:
    爬虫
    Django
    python多线程
    python基础
    深度学习_1_Tensorflow_1
    人工智能_5_决策树_随机森林
    人工智能_4_k近邻_贝叶斯_模型评估
    人工智能_3_机器学习_概述
    Python re 模块
    Python函数式编程
  • 原文地址:https://www.cnblogs.com/vanilla1996/p/5369880.html
Copyright © 2011-2022 走看看