Java: constructing a file from a URI?
- by AP257
I need to obtain a File object from a URI, working in Java, but keep getting a length of zero - though I know the file size is not zero.
I need the File object to pass to another constructor.
I'm not sure if it's because I'm constructing it in the wrong way? Here's my code:
File videoFile = new File(videoURI.getPath());
if (videoFile == null) {
Log.d(LOG_TAG, "File not found!");
return false;
}
Log.d(LOG_TAG, "about to upload, filepath: " + videoFile.getPath());
Log.d(LOG_TAG, "File length: " + String.valueOf(videoFile.length()));
The log output doesn't spit out 'File not found!', and prints a non-null path, but shows a length of 0.