は、私は、ファイルの保存機能があります。Windowsのユニバーサルアプリケーション - Javascriptを - - ファイルIO応答なし
function WINJSWrite(file, content) {
if (content.length <= 0) {
GameConsts.MyAlert("No data to save.");
}
// Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
Windows.Storage.CachedFileManager.deferUpdates(file);
// write to file
Windows.Storage.FileIO.writeTextAsync(file, content).done(function() {
// Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
// Completing updates may require Windows to ask for user input.
Windows.Storage.CachedFileManager.completeUpdatesAsync(file).done(function (updateStatus) {
if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) {
//WinJS.log && WinJS.log("File " + file.name + " was saved.", "sample", "status");
} else {
//WinJS.log && WinJS.log("File " + file.name + " couldn't be saved.", "sample", "status");
}
});
});
を};
localFolder.getFileAsync('myfile.txt').then(
function (file) {
// NEVER GETS HERE
if (file) {
WINJSWrite(file, content);
} else {
localFolder.createFileAsync("myfile.txt").done(
function (newFile) {
if (newFile) {
WINJSWrite(newFile, content);
}
});
}
});
しかし、コードが// NEVER GETS HERE
になることはありません:次のように
それから私はmyfile.txt
が存在するかどうかに応じて、これを呼び出します。
私は間違っていますか?
注:localFolder.getFileAsync('myfile.txt').then(
の代わりにlocalFolder.getFileAsync('myfile.txt').done(
を使用すると、ファイルが存在しないとのエラーが表示されます(ただし、わかります)。