以下指令检查路径中的文件是否存在:
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";
}
答案 0 :(得分:0)
知道了!
FileInfo info = new FileInfo(path);
if (info == null || info.Exists == false) { ... };