Reputation: 81
How do I access file after I save it to persistent data path on android? I looked all over my mobile files and I could not find the saved file. When I ran debugging it pointed me to location that does not exist on my mobile? storage/emulated/0
for code I use stream writer
string[][] output = new string[rowData.Count][];
for (int i = 0; i < output.Length; i++)
{
output[i] = rowData[i];
}
int length = output.GetLength(0);
string delimiter = ",";
StringBuilder sb = new StringBuilder();
for (int index = 0; index < length; index++)
sb.AppendLine(string.Join(delimiter, output[index]));
string filePath = getPath();
StreamWriter outStream = System.IO.File.CreateText(Application.persistentDataPath +
"/results" + settings.IdentificationNumber + ".csv");
outStream.WriteLine(sb);
outStream.Close();
I have no issue with getting this same code to work on pc.
Upvotes: 1
Views: 730
Reputation: 125275
To access the saved file, you first need to understand where Application.persistentDataPath
points to. This post shows where it points to on most platforms.
For Andoid, that's at:
/Data/Data/com.<companyname>.<productname>/files
When SD card is available, this is at:
/storage/sdcard0/Android/data/com.<companyname>.<productname>/files
It depends on the device model too. On some devices, it will not save on the SD card even when it is available.
Use Debug.Log
or the Text
component to log the Application.persistentDataPath + "/results" + settings.IdentificationNumber + ".csv"
path. This will show you where to look for the saved file. If it's not saved on the SD card but on /Data/Data/com.<companyname>.<productname>/files
, see this post for how to obtain the file on the /Data/Data
folder.
Upvotes: 3