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());
But it always gives me that the size is 0. What am I doing wrong?
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.
Like this:
InputStream is = context.getResources().openRawResource(R.raw.nameOfFile);
int sizeOfInputStram = is.available(); // Get the size of the stream
Try this lines:
InputStream ins = context.getResources().openRawResource (R.raw.video)
int videoSize = ins.available();
Try this:
AssetFileDescriptor sampleFD = getResources().openRawResourceFd(R.raw.video);
long size = sampleFD.getLength()
来源:https://stackoverflow.com/questions/6049926/get-the-size-of-an-android-file-resource