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?

Icy Creature
  • 1,875
  • 2
  • 28
  • 53
  • try `String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/folder/Save.spm";` instead of `String filePath = Environment.getExternalStorageDirectory() + "/folder/Save.spm"; ` – ρяσѕρєя K Oct 13 '12 at 17:22
  • It's "Save.spm" not "save.spm?" File names are case sensitive. – Simon Oct 13 '12 at 17:37
  • I have checked that as well the file path is right including upper and lower characters. – Icy Creature Oct 13 '12 at 17:44
  • Check my answer [here](http://stackoverflow.com/questions/12865267/java-io-filenotfoundexception-access-denied-even-though-ive-putted-permissions/12865325#12865325). First open the path, then via the path, open the file – Mohsen Afshin Oct 13 '12 at 20:14

1 Answers1

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.

Deepak Bala
  • 11,095
  • 2
  • 38
  • 49