document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail); } function gotFileEntry(fileEntry) { console.log(evt.target.error.code); } function fail(evt) { console.log(evt.target.error.code); }
答案 0 :(得分:0)
您只能在应用程序的Document文件夹中获取文件。
如果找不到该文件,您可以通过在getFile()
函数中使用{create:true}替换'null'来创建它,如此
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
console.log("gotFileEntry");
}
function fail(evt) {
console.log("Error : "+evt.code);
}
</script>