Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iPhone System.IO.File.Exists()不工作_C#_Ios_Unity3d_File Io_Path - Fatal编程技术网

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) { ... };