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

  • 相关阅读:
    第二次安卓作业
    第十一次作业
    第十一次上机练习
    第十次作业
    第十次上机练习
    第九次作业
    第九次上机练习
    添加用户 Android 6
    Android 5
    activity带数据跳转
  • 原文地址:https://www.cnblogs.com/xuchao0506/p/12843043.html
Copyright © 2011-2022 走看看