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?
file. length() returns the length of the file in bytes, as described in the Java 7 Documentation: Returns the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist.
Note: A dimension is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine dimension resources with other simple resources in the one XML file, under one <resources> element. The filename is arbitrary.
Resources are used for anything from defining colors, images, layouts, menus, and string values. The value of this is that nothing is hardcoded. Everything is defined in these resource files and then can be referenced within your application's code.
Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.
Try this:
AssetFileDescriptor sampleFD = getResources().openRawResourceFd(R.raw.video); long size = sampleFD.getLength()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With