如何在科尔多瓦安卓应用程序中的根级目录中而不是应用程序数据目录中写入文件



我正在构建一个Cordova安卓应用程序,并使用cordova-plugin-file在本地系统上写入文件。我使用的代码如下:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
    console.log('file system open: ' + fs.name);
    fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {
        console.log("fileEntry is file?" + fileEntry.isFile.toString());
        writeFile(fileEntry, null);
    }, onErrorCreateFile);
}, onErrorLoadFs);

文件newPersistentFile.txt将在数据目录中创建app。如何将文件写入系统根级目录,如/DownloadsNotifications等?

你想看看cordova.file目录(见文档)。

因此,对于下载:

window.requestFileSystem(cordova.file.externalRootDirectory + "Downloads", 0, function(fs) {
   console.log('file system open: ' + fs.name);
   ...
}

相关内容

最新更新