简体   繁体   中英

IsolatedStorageException when reading from file in Android App

I am developing a simple game in Unity and so far it works perfectly on PC. However when launching it in Android I am getting this error:

I/Unity (26449): IsolatedStorageException: Could not find a part of the path "/mnt/asec/es.uca.gii.dsh.traducinante-1/base.apk/Resources/items.json".

I don't really get what this is about but it seems like it's not reading from the json. This totally messes with my application because it's not getting the data I need to initialize pretty much everything I need for the game.

Here's the piece of code here this is happening:

string jsonString = File.ReadAllText(Application.dataPath + "/Resources/items.json");

What am I missing? How can it work on PC but not at all on Android? How can I do?

Try to use this approach:

FileStream fileStream = File.Open(Application.persistentDataPath + "/yourFileName.json", FileMode.Open);
using (StreamReader reader = new StreamReader(fileStream))
{
    string fileContent = reader.ReadToEnd();
    //do whatever you want
}

I solved it changing the way I am accessing the resource:

TextAsset txtAsset = Resources.Load("items") as TextAsset;
string jsonString = txtAsset.text;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM