我在我的资源中的raw文件夹中有一个视频文件。我想知道文件的大小。我有一段代码:
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。我做错了什么?
发布于 2011-05-19 03:28:14
您不能对资源使用File
。使用Resources
或AssetManager
获取资源的InputStream
,然后对其调用available()
方法。
如下所示:
InputStream is = context.getResources().openRawResource(R.raw.nameOfFile);
int sizeOfInputStram = is.available(); // Get the size of the stream
发布于 2013-04-10 00:03:37
试试这个:
AssetFileDescriptor sampleFD = getResources().openRawResourceFd(R.raw.video);
long size = sampleFD.getLength()
发布于 2011-05-19 03:29:33
试试下面这几行:
InputStream ins = context.getResources().openRawResource (R.raw.video)
int videoSize = ins.available();
https://stackoverflow.com/questions/6049926
复制相似问题