javascript - 使用 cordova-file-plugin 存储的文件在哪里
问题描述
我正在尝试在移动设备上创建一个 excel,我正在使用 android 进行测试,但它也应该适用于 iOS
我使用了文档 文档中的以下代码
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());
fileEntry.name == 'someFile.txt'
fileEntry.fullPath == '/someFile.txt'
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function() {
console.log("Successful file write...");
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log("Successful file read: " + this.result);
//displayFileData(fileEntry.fullPath + ": " + this.result);
};
reader.readAsText(file);
},);
};
fileWriter.onerror = function (e) {
console.log("Failed file write: " + e.toString());
};
let dataObj = new Blob(['some file data'], { type: 'text/plain' });
fileWriter.write(dataObj);
});
});
});
我尝试将前三行更改为以下行,结果相同
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) { ...
我得到以下控制台日志
file system open: persistent
fileEntry is file?true
Successful file write...
Successful file read: some file data
因此,该文件已创建并且我可以读取它,但是我没有收到任何提示或其他内容,然后我导航到 Android/data/com.myapp.app/files 上的文件并且我没有任何文件
解决方案
似乎文件正在保存,但我看不到它们,但我可以通过 cordova-file-plugin 读取它们
我将目标文件夹更改为
let ruta = cordova.file.externalRootDirectory
let directoryRoute = "myApp";
window.resolveLocalFileSystemURL(ruta, function (fs) {
fs.getDirectory(directoryRoute, { create: true }, function (fs2) {
fs2.getFile(fileName, { create: true, exclusive: false }
, function (fileEntry) { ...
如果不存在用于保存我的应用程序文档的文件夹,我正在创建 cordova.file.externalRootDirectory,这适用于 android,可能会对 iOS 进行更改
我将在几天后更新答案,当我有 iOS 的答案时,这可以帮助某人
推荐阅读
- wordpress - Wordpress plugin ABSPATH or die
- wordpress - Wordpress 在自定义模板文件中需要一个 php 文件
- amazon-web-services - EC2 和 Lightsail 之间的数据流量是否免费(在 EC2 计费中)?
- c++ - 运行时错误:引用绑定到“int”类型的空指针 (stl_vector.h)
- android - 没有在 RecyclerView 项目布局中获得点击的子项目的 id
- rust - 如何匹配 Rust 中的闭包
- amazon-web-services - 在创建 AWS 管理气流环境期间如何为日志组设置标记
- c++ - gluTessVertex() 的 data 参数究竟是什么?
- game-development - Godot反转由两个Vector2对象组成的选定矩形区域
- python - Telethon Telegram session_name 错误