android - 从 android 中的服务器返回文件大小 = -1

标签 android mysql

我正在制作一个Android应用程序,其中我从服务器获取存储在mysql数据库中的图像。所以我在下载之前需要文件大小,并且我正在使用此代码

       FileOutputStream fileOutput = new FileOutputStream(file);

         InputStream inputStream = urlConnection.getInputStream();  
     int totalSize = urlConnection.getContentLength();

但我总是得到totalsize = -11。我不知道为什么会发生这种情况。请帮助我解决这个问题

最佳答案

服务器似乎没有在响应 header 中设置Content-Length

关于android - 从 android 中的服务器返回文件大小 = -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39999409/

相关文章:

Mysql Select 语句动态转换时间戳

php - 在记录集的循环内循环

php - Apache2/phpmyadmin - PHP 不工作

android - Android 中来自 Sqlite 的 ListView

java - 如何使用 public <T extends View> T findViewById(int id);在Android Activity中编译sdk 26?

android - 将 long 转换为 Double 时遇到问题

android.graphics.Matrix -> postScale 是如何工作的

android - 强制关闭不会退出 android 应用程序,而是打开一个处于错误状态的先前 Activity

java - 多用户登录java(管理员,用户,教师)

php - 将 MySQL .sql 文件转换为 MS Access 数据库