安卓:获取资源文件的大小? [英] Android: Get the size of a file in resources?
本文介绍了安卓:获取资源文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的资源在原始文件夹中的视频文件。我想找到的文件的大小。 我有这块code:
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?
推荐答案
您无法使用文件
资源。使用资源
或 AssetManager
来获得的InputStream
的资源,然后调用就可以了用()
方法。
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
这篇关于安卓:获取资源文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文