• 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方式推送进度),涉及到后台计算进度问题,特此记录

  • 相关阅读:
    ORM之F和Q
    ORM查询
    Django
    jQuery基础
    DOM和BOM
    saas baas paas iaas 的理解
    分布式架构的演进过程
    tomcat 配置https 证书
    idea 学习总结
    简单数据库连接池-总结
  • 原文地址:https://www.cnblogs.com/xuchao0506/p/12843043.html
Copyright © 2020-2023  润新知