Android:下载前如何获取文件大小? [英] Android: how to get file size before download?

查看:136
本文介绍了Android:下载前如何获取文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在下载文件之前如何知道文件的大小?

我必须在我的应用程序中下载一些pdf。

I must download some pdf in my app.

我需要在开始下载文件大小之前,显示一个进度条,或通过标准的下载..通知用户

I need to have the filesize before start to download, to show a progress bar, or to notify the user with the standard 'downloading .. ' notification

如何获取具有新Url的文件大小(' http://mysite.net//mypdf.pdf ')?

How to get a file size having a new Url('http://mysite.net//mypdf.pdf') ?

推荐答案

final URLConnection connection = url.openConnection();
final int length = connection.getContentLength();

尝试使用 URLConnection.getContentLength 如上。如果服务器没有指定长度,那么您不能知道。

Try using URLConnection.getContentLength as above. If the server doesn't specify a length, then you can't know.

这篇关于Android:下载前如何获取文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆