Hello,
i am using unity 2017.1.0f3 and i am stuck on a problem. I can’t write in the Application.persistentDataPath folder and i catch no error
public void CreateFile()
{
StreamWriter file;
string fullPath = Application.persistentDataPath + "/test.txt";
try
{
if (!File.Exists(fullPath))
{
file = File.CreateText(fullPath);
file.WriteLine("test");
file.Close();
}
else
{
File.WriteAllText(fullPath, "test");
}
}
catch (Exception e)
{
}
}
It is one of the simplest test i’ve done but it’s not working. The app is trying to write in /storage/emulated0/Android/data/com.company.import/files/test.txt but no file is created.
I looked a little on my phone and noticed that an other app used an other path
/storage/3064-3934/Android/data/com.company.import/files/test.txt
I used this path in my script and it worked (so it’s not a permission issue). But i need a path that works on the majority of the devices.
Can somone help me on that ?
Phone used for testing : Samsung S5 SM-G900F android 6.0.1