Help Writing and reading files on android.

Hello, recently i’ve been working on an app in witch i’ll use Json files access my sql database.

I’m programing everyhink on C#, and using LitJson Plugin for Json files.

The code i need to fix is supposed to Write a Json file, then read it, but i think i micht be doing something wrong with the file directory of android…

i’m using:

        File.WriteAllText(Application.persistentDataPath + "/StreamingAssets/campoos.json", "[" + CamposData.ToString() + "]");    // To write my Json file


        CamposData = JsonMapper.ToObject(File.ReadAllText(Application.persistentDataPath + "/StreamingAssets/campoos.json")); // To read my Json file

The code was supposed to display some info of the Json file on screen. however, when on PC it works, but at Android devices i won’t.

The problem is that the StreamingAssets folder doesn’t exist on android. The streaming assets are packed into the JAR / APK file and you have to use

"jar:file://" + Application.dataPath + "!/assets/"

This works only with the WWW class as stated on the documentation page i’ve linked above. Of course you can’t “write” to that “folder” since it’s not a real folder. If you want to cache things in the persistentDataPath, you have to create any subfolders you like to use yourself. The persistentDataPath doesn’t contain any subfolders by default.

The easiest way to create folders is to use the DirectoryInfo class.

Please don’t close a question with “right answer selected” if there is no answer and of course no answer selected.