首页 新闻 会员 周边

JAVA中IOStream缓存数组设置大小的最优解是什么?

0
悬赏园豆:20 [待解决问题]

我编程实现将一个mp4文件复制到另一个目录下。想知道缓冲数组的大小设置为多少能使效率达到最高,有没有什么计算公式?代码如下:

package copy;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyMP4 {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        long startTime = System.currentTimeMillis();
        File file = new File("F:\\东山村.mp4");   //mp4大小136857*1024byte
        FileInputStream fis = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream("D:\\笔芯的东山村.mp4");
        //byte[] b = new byte[1024];   //用时2720 2545 2617 2718 2709
        //byte[] b = new byte[1024*10];   //用时875 850  709 729 773 788 884
        //byte[] b = new byte[1024*100];      //用时422 450 436 477 497 436  447
        byte[] b = new byte[1024*1024];        //用时695 739 702 641 746 730  870
        int l=0;
        while((l=fis.read(b))!=-1){
            fos.write(b, 0, l);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("复制mp4完成,用时"+(endTime-startTime));
    }

}
无知的家伙的主页 无知的家伙 | 初学一级 | 园豆:182
提问于:2017-08-18 16:07
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册