Java: constructing a file from a URI?

Posted by AP257 on Stack Overflow See other posts from Stack Overflow or by AP257
Published on 2010-02-28T16:09:28Z Indexed on 2010/05/06 3:08 UTC
Read the original article Hit count: 291

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about android