springboot文件上传 流的方式 后台计算上传进度
Posted ジ绯色月下ぎ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot文件上传 流的方式 后台计算上传进度相关的知识,希望对你有一定的参考价值。
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方式推送进度),涉及到后台计算进度问题,特此记录
以上是关于springboot文件上传 流的方式 后台计算上传进度的主要内容,如果未能解决你的问题,请参考以下文章