标签:IO
package com.chen.io1;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
*/
public class CopyVideo {
/**
/**
@param toFileName
*/
public static void baseCopyMethod2(String fromFileName,String toFileName) {
long startTime = System.currentTimeMillis();
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(fromFileName);
out = new FileOutputStream(toFileName);
byte[] buf = new byte[102];//缓冲区数组,减少硬盘的读取操作
int tempRead ;
while((tempRead=in.read(buf))>-1) {
out.write(buf);
out.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(in!=null)in.close();
if(out!=null)out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
long spendTime = endTime - startTime;
System.out.println("方法二,增加缓存后复制用时:"+ spendTime + "毫秒");
}
/**
/**
public static void main(String[] args) {
String fromFileName = "C:\Users\Administrator\Desktop\test.wmv";
String toFileName = "C:\Users\Administrator\Desktop\test1.wmv";
//baseCopyMethod(fromFileName,toFileName);
//baseCopyMethod2(fromFileName,toFileName);
//bufferedCopyMethod(fromFileName,toFileName);
bufferedCopyMethod(fromFileName,toFileName);
}
}
标签:IO
原文地址:http://blog.51cto.com/12694001/2125377