安卓:如何下载之前获取文件的大小? [英] Android: how to get file size before download?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/2983073/how-to-know-the-size-of-a-file-before-downloading-it\">How下载前知道一个文件的大小?
块引用>我必须下载一些PDF在我的应用程序。
我需要有文件大小开始之前下载,显示一个进度条,或者用标准的通知用户下载..通知
如何获得有一个新的URL('http://mysite.net//mypdf.pdf')的文件大小?
解决方案最后的URLConnection连接= url.openConnection();
最终诠释长度= connection.getContentLength();请尝试使用
的URLConnection。 getContentLength
如上。如果服务器没有指定长度,那么你可以不知道。Possible Duplicate:
How to know the size of a file before downloading it?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
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();
Try using
URLConnection.getContentLength
as above. If the server doesn't specify a length, then you can't know.这篇关于安卓:如何下载之前获取文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!