I am trying to get text file read/write access at Unity for iOs project. What I did was
//Read
StreamReader reader = new StreamReader(Application.persistentDataPath + "/record.txt");
string record = reader.ReadToEnd ();
string[] records = record.Split(new string[] { " " }, StringSplitOptions.None);
firstname = records [0]; lastname = records [1]; loginName = records [2]; password = records [3];
reader.Close();
email.transform.GetComponent<InputField> ().text = loginName;
pwd.transform.GetComponent<InputField> ().text = password;
//Write
File.WriteAllText(Application.persistentDataPath + "/record.txt", String.Empty);
//File.Create (Application.persistentDataPath + "/record.txt").Close ();
StreamWriter writer = new StreamWriter (Application.persistentDataPath + "/record.txt", true);
writer.WriteLine (Login.firstname + " " + Login.lastname + " " + Login.loginName + " " + Login.password);
writer.Close ();
Then I include the file to Build Phases -> Copy Bundle Resources, so the file is inside the project. But when I run the app inside the device, I can't read file and got message as
IsolatedStorageException: Could not find file "/var/mobile/Containers/Data/Application/D48E51C7-F2EE-48CF-9B84-6602CE135EBC/Documents/record.txt".
at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0
at System.IO.File.OpenRead (System.String path) [0x00000] in <filename unknown>:0
What could be wrong?