开发者

Android Uri to Filesize [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Android: Get the size of a file in resources?

I want to upload a file to a WebServer. To show the progress of the upload I need to know the complete size of the file. Since I have only the Uri of the file (got it from an Intent), I have no cha开发者_StackOverflownce to get at the file's size. My workaround is to open an InputStream and count the bytes that are read on this InputStream. But this is circuitous. Is there an easier/conventional way to solve this issue?

Thanks


You can get the size of the file in bytes thus:

File f = new File(uri.getPath());
long size = f.length();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜