0

以下指令检查路径中的文件是否存在:

string path = GetiPhoneDocumentsPath();
if (System.IO.File.Exists(path) == false) XmlTextWriter textWriter = new XmlTextWriter(path,null);

然后,如果该文件不存在,它会创建一个新文件,它在统一执行中运行良好,但是当我在 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";
}
4

1 回答 1

0

知道了!

FileInfo info = new FileInfo(path);
    if (info == null || info.Exists == false) { ... };
于 2011-02-11T00:49:17.823 回答