I am working on a 2D game which will be later used as advertisement activity on a stall, I need to store user information, Name, Number, Email and score. There data may exce
For anyone else that comes here because they're trying to access Application.StreamingDataPath (or anything else within an APK for that matter) you cannot simply use the File api as discussed in Fattie's response. You need to use a web request as the APK is essentially a compressed folder and System.IO cannot access the internals of these packages.
You will need to use UnityWebRequest to GET the data from the desired location within the PKG. You can include raw files in your game by adding a folder anywhere in the project and calling it StreamingAssets (Resource folders are reconstructed inside the APK and can't be directly accessed, they're also loaded into memory at runtime which makes the game start very slowly), then point your UWR at Application.streamingDataPath and get the data from request.downloadHandler.data.
For saving new data, you have to use Application.persistantDataPath, at which point using System.IO.File is just fine.
Here is an example of grabbing data out of the APK!/assets/ folder (where android puts the StreamingAssets folder) and then saving it to a location for later use.
public IEnumerator GetSomeDataAndThenSave(string path)
{
UnityWebRequest request = UnityWebRequest.Get(path);
request.Send();
while(!request.isDone)
{
yield return null;
}
if (!request.isNetworkError && (request.responseCode == 0 || request.responseCode == (long)System.Net.HttpStatusCode.OK))
{
WrapperClass yourClassList = new WrapperClass();
YourClassList.members = JsonUtility.FromJson(request.downloadHandler.text);
var bytes = System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(instance));
File.WriteAllBytes(Application.persistentDataPath + "/SubDirectory/" + Path.GetFileName(path), bytes);
}
request.Dispose();
}
Hope that clears things up for anyone else having the same issue.