File.WriteAllText() on Android (Json file)

Hello, I am trying to rewrite a json file to replace old data with new one on an Android device, on the PC it works perfectly just like this:

File.WriteAllText(Application.dataPath + "/Resources/Items.json", json);

where the “json” variable is a string containing the new information.

How can I accomplish this on an Android device? I’ve tried everything but nothing seems to work correctly.

string jsonPath = Application.streamingAssetsPath + "/Items.json";
File.WriteAllText(jsonPath, json);

This is the code I have for Android, but it dosent work, what should I change?

Thank you in advance.

folderPath = (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer ? Application.persistentDataPath : Application.dataPath)+“/myDataFolder/”;

 filePath = folderPath  + fileName + ".txt";
 
 if (!Directory.Exists (folderPath)) {
                 Directory.CreateDirectory (folderPath);    
             }
 
             File.WriteAllText(filePath, "hello world");

We tried to use the solution from ExtinctSpecie, but writing to the file didn’t work, so we added a .Close() after Creating the File and now it works. Here our method to get the File path:

   public string GetPath()
    {
        string folderPath = (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer ? Application.persistentDataPath : Application.dataPath) + "/myDataFolder/";
        string filePath = folderPath + "myFile.json";
        if (!Directory.Exists(folderPath))
        {
            Directory.CreateDirectory(folderPath); 
        }
        if (!File.Exists(filePath)) 
        {
            File.Create(filePath).Close();
            File.WriteAllText(filePath, "myJsonText");
        }
		return  filePath ;
    }