【问题标题】:Create directory with Cordova FileWriter使用 Cordova FileWriter 创建目录
【发布时间】:2015-07-31 10:15:03
【问题描述】:

我想使用 PhoneGap 和文件写入器将文件保存在新目录中。 我有这个代码:

fileName = fileSystem.root.fullPath+"/test.html";
var writer = new FileWriter(fileName);
writer.write("ttteeeesssttttt", false);

有了这个,我可以创建 test.html 文件并且它可以工作。 但是当我将路径更改为:

 fileName = fileSystem.root.fullPath+"/test/test.html";

它不起作用....

有没有简单的方法来解决这个问题,还是我应该先在其他函数中创建目录?

谢谢! :)

【问题讨论】:

  • 您需要明确创建目录,然后才能在其中创建文件

标签: javascript cordova mobile phonegap-plugins


【解决方案1】:

当 onDocumentReady 被触发时检查这个:

    function CreateFolder(){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, creatingFolder,       error);
   }

这会创建文件夹:

 function creatingFolder(fileSystem) {
    var entry = fileSystem.root;
    entry.getDirectory("test", {create: true, exclusive: false}, win, error);
}


 function win(dir) {
  console.log("Created dir "+dir.name);
  console.log("Created dir "+dir.fullPath);
  console.log("Created dir NativePath" + dir.nativeURL);
}

【讨论】:

    猜你喜欢
    • 2018-10-05
    • 2013-09-26
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多