package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class DownTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
File iFile = new File("F:\\新建文件夹\\肖申克的救赎.重制版.国英双语.1994.中英字幕£CMCT暮雨潇潇\\[肖申克的救赎(国英双语)].The.Shawshank.Redemption.1994.BluRay.720p.x264.AC3.2Audios-CMCT.mkv");
File oFile = new File("d:\\test\\[肖申克的救赎(国英双语)].The.Shawshank.Redemption.1994.BluRay.720p.x264.AC3.2Audios-CMCT.mkv");
FileInputStream fis = null;
FileOutputStream fos = null;
long s = 0; //记录开始时间
long sta = 0;//记录每秒开始时间
long end = 0;//记录每次写入时间
long oldlength = 0;//写入前文件大写
long newlength = 0;//记录1秒后写入大小
byte[] buf = new byte[1024];// 定义临时数组
int tlength = 0;//定义临时变量保存长度。
try {
fis = new FileInputStream(iFile);
fos = new FileOutputStream(oFile);
s = sta = System.currentTimeMillis();//得到当前时间毫秒数
oldlength = oFile.length();//得到旧文件长度
while((tlength = fis.read(buf)) != -1){
fos.write(buf, 0, tlength);
end = System.currentTimeMillis();
if(end - sta > 1024){
sta = end;
newlength = oFile.length();
System.out.println("每秒钟传送"+ (newlength - oldlength) / (1024 * 1024) + "M");
oldlength = newlength;
}
}
System.out.println("总共耗时" + (end - s) / (1000 *60) + "分" + ((end - s) % (1000 *60)) / 1000 + "秒");
} catch (Exception e) {
// TODO: handle exception
} finally{
try {
fos.flush();
fos.close();
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
FileInputStream复制文件,实时显示速度
最新推荐文章于 2023-12-21 14:32:52 发布