Android file.exists() not working
<p>Hallo,</p>

<p>Here's some code which writes a data class to a file, then checks to see that the file exists. I can see that the file exists on the emulator, but file.exists() and therefore saveStateAvailable() returns false.</p>

<pre><code>    private void saveStateFile() {
    /*DEBUG*/Log.d(this.getClass().getName(), "saveStateFile: Started");
    mGameData = getGameData();
        try {
            FileOutputStream fileoutputstream = openFileOutput(mGameData.pilotName + STATE_FILE_EXTENSION, Context.MODE_WORLD_WRITEABLE);
            ObjectOutputStream objectoutputstream;
            objectoutputstream = new ObjectOutputStream(fileoutputstream);
            objectoutputstream.writeObject(mGameData);
            objectoutputstream.close();
            fileoutputstream.close();
            /*DEBUG*/Log.i(this.getClass().getName(), "saveStateFile: State saved to "+mGameData.pilotName + STATE_FILE_EXTENSION);
        } catch (IOException e) {
            /*DEBUG*/Log.e(this.getClass().getName(), "saveStateFile: Error writing data state file, "+mGameData.pilotName + STATE_FILE_EXTENSION);
            e.printStackTrace();
        }
    /*DEBUG*/Log.d(this.getClass().getName(), "saveStateFile: Finished stateFileAvailable="+stateFileAvailable());
}
private boolean stateFileAvailable() {
    File file = new File(mGameData.pilotName + STATE_FILE_EXTENSION);
    /*DEBUG*/Log.d(this.getClass().getName(), "stateFileAvailable: Called ("+mGameData.pilotName + STATE_FILE_EXTENSION+" exists = "+file.exists()+")");
    return file.exists();
}
</code></pre>

<p>Any ideas?</p>

<p>-Frink</p>
