# Unity Isolatedstorageexception : Could Not Find File

This topic is 724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to save/load player data from a file using the persistenceDataPath using the following code:

private void Save()
{
if (File.Exists (Application.persistentDataPath + "/playerInfo.dat"))
{
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
data.userExperience = userExperience;
bf.Serialize (file, data);
file.Close ();
}
}

{
if (File.Exists (Application.persistentDataPath + "/playerInfo.dat"))
{
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat ", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
userExperience = data.userExperience;
file.Close ();
}
}

[Serializable]
class PlayerData
{
public int userExperience;
}


It works fine if I play the game with Unity Editor. However, on Android, when I try to execute this line of code in Load():

FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat ", FileMode.Open);

I get this error:

The file does exist since the code pass through the if(File.Exist...) and it works when I try to access the file from the Save() method.

I really don't know what it could be since the code that open the file in Save() and Load() is the same.

Edited by RationeUtor

##### Share on other sites

I don't know if this is relevant but

if (File.Exists (Application.persistentDataPath + "/playerInfo.dat"))
{
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat ", FileMode.Open);

On the second line you have a space after .dat. Again I don't know if that is something but delete it and see if ti helps particularly as it thinks the file exists from the first line.

##### Share on other sites

I don't know if this is relevant but

if (File.Exists (Application.persistentDataPath + "/playerInfo.dat"))
{
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat ", FileMode.Open);

On the second line you have a space after .dat. Again I don't know if that is something but delete it and see if ti helps particularly as it thinks the file exists from the first line.

Yes it was that! LOL. Lost one entire day for a type error

Apparently when playing from the Unity editor it was still able to access the path even with the space at the end.

Thank you!

Edited by RationeUtor

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631750
• Total Posts
3002051
×