- Home /
Write to iPhone file system Access Denied
When I try to use System.IO to write a text file to iPhone, it shows error Access to path "/xxx/xxx" denied. How can I solve it?
Answer by mohanrao164 · Aug 30, 2011 at 09:40 AM
it is not that easy to read or write file in iphone we have to give the specific path in order to read or write.
here is the sample code
using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
public static class GameManager
{
private static string path;
public static void starting ()
{
path = Application.dataPath.Substring (0, Application.dataPath.Length - 20 )+"Documents";
}
//---------------------file handleres------------------------------
public static void writeToFile(string filename , int value)
{
StreamWriter sw = new StreamWriter(path+"/"+filename);
string temp = value.ToString();
sw.Write("");
sw.WriteLine(temp);
sw.Close();
}
public static int ReadFromFile(string filename )
{
StreamReader sr = new StreamReader(path+"/"+filename);
string temp = sr.ReadLine();
int anothertemp = int.Parse(temp);
sr.Close();
return anothertemp;
}
//---------------------file handleres------------------------------
}
i think it will work . let me now if any problem.
I have found it. Each app only have access to "Documents" folder under it. That's the place we could use. There is actually no nid to Substring it.
Answer by andrew-fray · Oct 14, 2014 at 09:58 AM
The implication is that you're writing to a path constructed with Application.dataPath. That's the game assets folder, and could be overwritten when installing an update. Instead, use Application.persistentDataPath http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html. You have permissions for that folder, and it won't be destroyed on update.
Your answer
Follow this Question
Related Questions
unzip zip file content into directory on iphone 1 Answer
Saving login info locally Android iPhone 0 Answers
iPhone Resolution Screen Switch 0 Answers
iPhone shader help to simulate TV static, works but not on iPhone. 1 Answer
Base sdk missing 1 Answer