iPhone System.IO.File.Exists()无效

问题描述 投票:0回答:1

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

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";
}
c# ios unity3d file-io path
1个回答
0
投票

得到它了!

FileInfo info = new FileInfo(path);
    if (info == null || info.Exists == false) { ... };
© www.soinside.com 2019 - 2024. All rights reserved.