Javascript 使用Cordova FileWriter创建目录

Javascript 使用Cordova FileWriter创建目录,javascript,cordova,mobile,phonegap-plugins,Javascript,Cordova,Mobile,Phonegap Plugins,我想用PhoneGap和filewriter在新目录中保护一个文件。 我有以下代码: fileName = fileSystem.root.fullPath+"/test.html"; var writer = new FileWriter(fileName); writer.write("ttteeeesssttttt", false); 有了这个,我可以创建test.html文件,它就可以工作了。 但当我将路径更改为: fileName = fileSystem.root.fullPat

我想用PhoneGap和filewriter在新目录中保护一个文件。 我有以下代码:

fileName = fileSystem.root.fullPath+"/test.html";
var writer = new FileWriter(fileName);
writer.write("ttteeeesssttttt", false);
有了这个,我可以创建test.html文件,它就可以工作了。 但当我将路径更改为:

 fileName = fileSystem.root.fullPath+"/test/test.html";
它不起作用

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


谢谢!:)

在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);
}

当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);
}

当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);
}

当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);
}

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