Jump to content
  • Advertisement
Sign in to follow this  
RationeUtor

Unity Isolatedstorageexception : Could Not Find File

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

If you intended to correct an error in the post then please contact us.

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 ();
        }
    }

private void Load() 
{   
    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: 

 

UdjCG.png

 

 

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!