标签:stat gre size number temp cti 推送 inpu sock
public static void main(String[] args) throws Exception {
String path = "f:/svn/t_dictionary.txt";
File file = new File(path);//源文件
Long fsize = file.length();//获取文件大小
FileInputStream in = new FileInputStream(file);
//目标文件
FileOutputStream out = new FileOutputStream("f:/svn/temp/t_dictionary.txt");
byte[] buffer = new byte[1024];
int bz = buffer.length;
int readNumber = 0;
long progress = 0;//进度数值 12%显示的是取整 12
int time = 0;//循环的次数
while((readNumber = in.read(buffer)) != -1){
time++;
progress = time*bz*100/fsize;
out.write(buffer);
System.out.println(time+" ======> "+ progress);
}
}
说明:要做一个文件上传并且还带有进度条(websocket方式推送进度),涉及到后台计算进度问题,特此记录
标签:stat gre size number temp cti 推送 inpu sock
原文地址:https://www.cnblogs.com/xuchao0506/p/12843043.html