0

次の手順では、パスにあるファイルが存在するかどうかを確認します。

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";
}
4

1 に答える 1

0

とった!

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