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);}

     
  • 相关阅读:
    转:修改虚拟机参数
    NhiberNate 和linq学习博客园网址
    如何配置sqlserver 以允许远程连接
    Mongodb安装配置文档
    IIS安装和配置
    Mvc篇
    在Castle中使用nhibernate
    多线程
    WCF REST系列文章汇总(共9篇)
    测试Api工具Fiddler
  • 原文地址:https://www.cnblogs.com/vanilla1996/p/5369880.html
Copyright © 2011-2022 走看看