getContentLength() 指为 -1 的解决办法

在这个坑里3个多小时啊。这里不得不抱怨下,国内的资料坑爹,全部copy不说,还是错的。

解决办法:

在服务端加入代码:

   File file = new File(path); //path为要下载的文件路径

response.setContentLengthLong(file.length()); //对应于long getContentLengthLong()或者 int getContentLength()。


原文地址:https://www.cnblogs.com/xiangxinhouse/p/8647915.html