Application.dataPath doesnt work in Android!

Hi.

I have this line of code:

string json = _ReadFromFile(Path.Combine(Application.dataPath, "Data_I18N", "LocalizationData.json"));

The folder Data_I18N is inside Assets folder.

In pc is working perfectly but in Android no.

For android or IOS is another approach?

Thank you

Its sounds like this way is wrong way.

I need to use it as textasset…I need to find an way because I am using a static class and cant simply declare [SerializeField]…

So I tryed it but isnt working too:
var jsonTextFile = Resources.Load(“Data_I18N/LocalizationData”);
UnityEngine.Debug.Log(jsonTextFile.text);

This file is fixed, I dont need to change it,only read. But I have another file where I am saving data:
string filePath = Application.persistentDataPath + “SettingData.json”;
Thas isnt working too.

There is no assets folder in a build.

You probably want to be using StreamingAssets: Unity - Manual: Streaming Assets

Sorry, I am in circles here.

I am using this code:

        string path = Path.Combine(Application.streamingAssetsPath, "Data_I18N", "LocalizationData.json");
        if (Application.platform == RuntimePlatform.Android)
        {
            UnityWebRequest www = UnityWebRequest.Get(path);
            www.SendWebRequest();
            while (!www.isDone) ;
            string json = www.downloadHandler.text;
            val.text = json;
        }
        else
        {
            if (File.Exists(path))
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    string json = reader.ReadToEnd();
                    val.text = json;
                }
            }
            else
            {
                val.text = "file not found";
            }
        }

I create a folder called StreamingAssets and inside it I put my json.
Is possible that the file cant exist there in mobile? Like be deleted? Because how I can protec the code is doesnt exist?

I dont have IOS, but code will work in?

If I use [SerializeField] TextAsset t; to get my json and parse it, it will be more safer?
My fear is the user delete data like cleaning cache or something and stop all the app.

I suggest reading the documentation better. The folder should be called StreamingAssets, like it says in the documentation.

Then refer to the right documentation for loading raw files for your specific platform, as it varies per-platform.

I mean do you have any reason for it not to be built into your game’s assets?

If not, then just reference it the normal Unity way.

oops, sorry, the folder was rigth, I wrote wrong here, sorry

Probably I dont know how reference files in static class.

All my localizations works inside “public static class Data” class.

And I dont know how load file from it. This class cant be attached in gameobject and not accept [SerializeField]

Do you have any sugestion?

And thanks for attention…

Reference the text asset in a scriptable object. Put the SO in a resources folder, and load it via Resources.