我试过writing/reading
一个文件phonegap+android
,这里是设置:
$(document).ready(function() { document.addEventListener("deviceready", deviceready, true); $(document).bind("deviceready", function(){ //writeFile(); //readFile(); }); }); function deviceready() { writeFile(); readFile(); } // This is just to do this. function readFile() { var d = navigator.file.read('/sdcard/foo.xml', success(), fail()); console.warn(d); } function writeFile() { navigator.file.write('/sdcard/foo.xml', "This is a test of writing to a file", success(), fail()); }
但在Android 2.2的模拟器上,我收到以下错误消息:
08-06 14:21:29.428: INFO/Web Console(936): Error in success callback: Network Status1 = TypeError: Result of expression 'navigator.file' [undefined] is not an object. at file:///android_asset/www/phonegap.0.9.6.js:649
可能会遗漏什么,可以尝试什么?