获取Android文件资源的大小? [英] Get the size of an Android file resource?
本文介绍了获取Android文件资源的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的资源的原始文件夹中有一个视频文件.我想找到文件的大小. 我有这段代码:
I have a video file in the raw folder in my resources. I want to find the size of the file. I have this piece of code:
Uri filePath = Uri.parse("android.resource://com.android.FileTransfer/" + R.raw.video);
File videoFile = new File(filePath.getPath());
Log.v("LOG", "FILE SIZE "+videoFile.length());
但是它总是让我知道大小为0.我在做什么错了?
But it always gives me that the size is 0. What am I doing wrong?
推荐答案
您不能将File
用于资源.使用Resources
或AssetManager
获取资源的InputStream
,然后在其上调用available()
方法.
You can't use File
for resources. Use Resources
or AssetManager
to get an InputStream
to the resource, then call the available()
method on it.
赞:
InputStream is = context.getResources().openRawResource(R.raw.nameOfFile);
int sizeOfInputStram = is.available(); // Get the size of the stream
这篇关于获取Android文件资源的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文