我正在构建一个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
。如何将文件写入系统根级目录,如/Downloads
、Notifications
等?
你想看看cordova.file目录(见文档)。
因此,对于下载:
window.requestFileSystem(cordova.file.externalRootDirectory + "Downloads", 0, function(fs) {
console.log('file system open: ' + fs.name);
...
}