我知道这个问题以前被问过很多次,但我无论如何都解决不了。 我能够在sdcard上的目录中写入一个文本文件(android 4),但无法使用以下代码读取它:
function get_file () {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, getFilesystem, fail);
}
function getFilesystem(fs) {
alert("getFilesystem -> backup.txt"); // OK !
// alert("filesystem.name: "+fileSystem.name); // = persistent
// alert("filesystem.root.name: "+fileSystem.root.name); // = long number
//
fs.root.getFile("../../../../../../sdcard/test/backup.txt", {create: false, exclusive: false},
function(fileEntry) {
alert(fileEntry.fullPath); // shows that my path is appended to "data/.."
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
alert(+evt.target.result); // NOT SHOWING !
};
reader.readAsText(file);
}, fail);
}, fail);
}
我使用writer函数将文件写入sdcard/test目录中,使用../的顺序-这是一个丑陋的代码,但有效!但是,fs.root.getFile的工作方式不同-它返回的fullPath信息显示我的给定路径被附加到“/data/data/com.appname/files”,而不是替换它!由于我从未收到警报消息,因此onloadend函数显然无法正常工作,也没有收到错误消息。将路径更改为“file:///sdcard/test”或“sdcard/test”也没有任何效果。非常感谢您的帮助-提前致谢!Chris