Android app: IsolatedStorageException when reading from file
My app runs perfectly in PC, but when testing it in Android I am getting this error when launching it:
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 know what this is about but it's totally messing with my app because it's not reading the data form items.json and I need that.
Here's where this is happening:
string jsonString = File.ReadAllText(Application.dataPath + "/Resources/items.json");
Why does it work on PC but I get this error in Android? What am I missing? What should I do?
I'm having the same issue, did you ever find the solution?
Same thing happened here. I thought it was the audio messing up my game. Turns out it was IsolatedStorageException.
Here's a log with full stack trace:
IsolatedStorageException: Could not find a part of the path "/mnt/asec/com.company.appname-2/base.apk/Resources/Values/Quiz.json". System.IO.FileStream..ctor (System.String path, File$$anonymous$$ode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:290) System.IO.FileStream..ctor (System.String path, File$$anonymous$$ode mode, FileAccess access, FileShare share) System.IO.File.OpenRead (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:363) System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrder$$anonymous$$arks, Int32 bufferSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:167) System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding) System.IO.File.ReadAllText (System.String path, System.Text.Encoding encoding) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:587) System.IO.File.ReadAllText (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:582) $$anonymous$$yGame.$$anonymous$$ain.Awake () (at D:/ProjectDir/$$anonymous$$yGame/Assets/Scripts/Game/$$anonymous$$ain.cs:1xx)
Answer by HDX13 · Aug 16, 2017 at 04:56 AM
As described in the forums about IsolatedStorageException, @amanpu mentions that we should use TextAsset class to load our text (JSON) file.
TextAsset jsonData = Resources.Load<TextAsset>("Values/JSONData"); // dataObj = JsonConvert.DeserializeObject<List<DataValues>>(jsonData.text); // or use this dataObj = JsonUtility.FromJson<List<DataValues>>(jsonData.text);
Note: The first one uses Newtonsoft.Json library. Unity uses the second one.
Your answer
![](https://koobas.hobune.stream/wayback/20220612060559im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
File explorer for Windows and Android 0 Answers
Create a PDF file for Android and iOS 0 Answers
SQLite exception on Android 0 Answers
File.Move() on Android doesn't seem to work. 0 Answers
How to duplicate a file and save it in a new folder? 0 Answers