您使用什么版本的 Cordova?从 BlackBerry WebWorks(OS 5.0 及更高版本)开始支持
Cordova File-API 。
我是否正确假设您只想读取(和写入)该文件?
如果是这样,您可以尝试使用Cordova File-Reader和Cordova File-Writer。
文件阅读器
function win(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("read success");
console.log(evt.target.result);
};
reader.readAsText(file);
};
var fail = function(evt) {
console.log(error.code);
};
entry.file(win, fail);
文件编写器
function win(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.seek(writer.length);
writer.write("appended text");
};
var fail = function(evt) {
console.log(error.code);
};
entry.createWriter(win, fail);
否则试试那个片段(代码是一个旧项目,但当时工作)
<script type="text/javascript" charset="utf-8" src="css-js/phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
var path = "readme.txt";
fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write("some sample text");
我希望我能帮助你,最好的问候 F481