android - 如何在 Cordova android 应用程序的根目录而不是应用程序数据目录中写入文件?
问题描述
我正在构建一个 Cordova android 应用程序并用于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 目录(请参阅docs)。
所以对于下载:
window.requestFileSystem(cordova.file.externalRootDirectory + "Downloads", 0, function(fs) {
console.log('file system open: ' + fs.name);
...
}
推荐阅读
- xml - 使用 PowerShell 替换 XML 文件中所有对象的值
- html - 如何始终在移动设备和 iPad 上显示数字输入微调器
- visual-c++ - std::max 给出错误 C2064:术语不计算为采用 2 个参数的函数
- html - Vimeo 嵌入没有全宽
- distance - Google Geocoding API 返回部分匹配的地址
- postgresql - 使用 spring boot 和 postgres 正确设置 docker compose
- python - 加载预训练的 fasttext 模型
- php - 如何设置多部分边界 ubuntu 20.04
- spring-mvc - Jacson Spring MVC 从 @RequstMapping 返回字符串作为原始 JSON
- mysql - 两个 Select 语句合二为一