Skip to content Skip to sidebar Skip to footer

Context.openfileinput() Returning Null When Trying To Access A Stored File

Currently, I have the following code for saving a Web Archive and then getting it as a FileInputStream. However, the channel within webContent remains null and a FileNotFoundExcept

Solution 1:

openFileInput() doesn't accept paths, only a file name if you want to access a path.

Use this instead:

Filefile=newFile(this.getFilesDir().getAbsolutePath() + (WEB_PREFIX + postId));

EDIT: You need to make sure you are saving and retrieving the file from the same place. Give this a go:

Note: I'm not sure you need File.separator but try with and without it and see which one works.

Stringpath= context.getFilesDir().getAbsolutePath()
                + File.separator + WEB_PREFIX + postId;
        webView.saveWebArchive(path);
        FileInputStreamwebContent=null;
        try {
            webContent = newFile(path);
        } catch (FileNotFoundException e) {
            Log.d("onPageFinished()", "FileNotFoundException");
            e.printStackTrace();
        }

Post a Comment for "Context.openfileinput() Returning Null When Trying To Access A Stored File"