[SOLVED]File don't save in persistentDataPath

The txt file refuse to save in persistentDataPath and it get saved in project folder or in game folder if build

if (!Directory.Exists(Application.persistentDataPath + "/Maps"))
            Directory.CreateDirectory(Application.persistentDataPath + "/Maps");

        if (!File.Exists(path + "Level01.txt"))
        {
            TextAsset l01 = Resources.Load("Level01") as TextAsset;

            string data = l01.text.Replace(Environment.NewLine, string.Empty);

            string[] dataArray = data.Split('-');

            //File.WriteAllText(path + "Level01.txt", data);
            StreamWriter sr = new StreamWriter(path + "Level01.txt", true);
            for (int i = 0; i < dataArray.Length; i++)
            {
                if(i == dataArray.Length -1)
                    sr.WriteLine(dataArray*);*

else
sr.WriteLine(dataArray + “-”);
}
sr.Close();
}
If I change to dataPath it refuse to create folder.
Anyone have any idea what is happening ? I use the latest version of unity 2019

It seems you’re not saving the string path.
The best approach is to use a string and call just one time Application.persistentDataPath.

Try changing this:

if (!Directory.Exists(Application.persistentDataPath + "/Maps"))
             Directory.CreateDirectory(Application.persistentDataPath + "/Maps");

Into this:

path = Directory.Exists(Application.persistentDataPath + "/Maps";
if (!Directory.Exists(path ))
             Directory.CreateDirectory(path);

 if (!File.Exists(path + "/Level01.txt"))
 ...