利用struts2框架上传文件时,如果想要获取上传文件的大小可以利用下面的方式进行:

      FileInputStream ins = new FileInputStream(file);
         if (ins.available() > 1024 * 1024 * 3) {
         System.out.println("上传的文件不能超过3M,请重新上传");
         }

或者下面的方式:

File file = new File(uploadObjectPath);
         if (file.length() > 1024 * 1024 * 3) {
         System.out.println("上传的文件不能超过3M,请重新上传");
         }

 

相关文章:

  • 2021-07-01
  • 2022-12-23
  • 2022-02-07
  • 2022-02-18
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
猜你喜欢
  • 2022-01-03
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案