C# iPhone System.IO.File.Exists()不工作
以下指令检查路径处的文件是否存在:C# iPhone System.IO.File.Exists()不工作,c#,ios,unity3d,file-io,path,C#,Ios,Unity3d,File Io,Path,以下指令检查路径处的文件是否存在: string path = GetiPhoneDocumentsPath(); if (System.IO.File.Exists(path) == false) XmlTextWriter textWriter = new XmlTextWriter(path,null); 然后,如果文件不存在,它会创建一个新文件,它在unity执行中运行良好,但是当我在iphone中执行程序时,该文件永远不会被创建 以下是获取路径的函数: public static s
string path = GetiPhoneDocumentsPath();
if (System.IO.File.Exists(path) == false) XmlTextWriter textWriter = new XmlTextWriter(path,null);
然后,如果文件不存在,它会创建一个新文件,它在unity执行中运行良好,但是当我在iphone中执行程序时,该文件永远不会被创建
以下是获取路径的函数:
public static string GetiPhoneDocumentsPath()
{
// Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
// Application.dataPath returns
// /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
// Strip "/Data" from path
string path = Application.dataPath.Substring(0, Application.dataPath.Length - 5);
// Strip application name
path = path.Substring(0, path.LastIndexOf('/'));
return path + "/Documents/myFile.xml";
}
明白了
FileInfo info = new FileInfo(path);
if (info == null || info.Exists == false) { ... };