0

I'm trying to read from a file but i'm getting false on the check. I can't see why this is happning, The file exist i have a multible time just to be sure.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

I also have included this in the AndroidManifest.xml file so that is not the problem either.

    String filePath = Environment.getExternalStorageDirectory() + "/folder/Save.spm";
    File filecheck = new File(filePath);
    if(filecheck.exists() == false)
    {
        return false;
    }
    FileInputStream file = new FileInputStream(filePath);
    DataInputStream input = new DataInputStream(file);

Why does android claim that the file does not exist?

4
  • try String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/folder/Save.spm"; instead of String filePath = Environment.getExternalStorageDirectory() + "/folder/Save.spm"; Commented Oct 13, 2012 at 17:22
  • It's "Save.spm" not "save.spm?" File names are case sensitive. Commented Oct 13, 2012 at 17:37
  • I have checked that as well the file path is right including upper and lower characters. Commented Oct 13, 2012 at 17:44
  • Check my answer here. First open the path, then via the path, open the file Commented Oct 13, 2012 at 20:14

1 Answer 1

1

How did you check that the file exists ? Have your tried using the ADB pull command to retrieve the file back from the emulator (if you are using one) ?

adb pull /path/to/file

Get the absolute path for filecheck and try that. It is also possible that you are mistaking the application cache directory with the external storage. Or may be there is more than one external storage and you are looking at the wrong one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.