springboot文件上传 流的方式 后台计算上传进度
2021-01-27 16:15
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);
}
}
上一篇:python基础学习D4
下一篇:spring 事务原理
文章标题:springboot文件上传 流的方式 后台计算上传进度
文章链接:http://soscw.com/index.php/essay/47825.html