javascript - Apache cordova - 无法写入android中的文件

标签 javascript android apache cordova cordova-3

我正在尝试在 JavaScript 中使用 cordova 的 api 在 PERSISTENT(sd 卡)存储中创建一个文件。我能够创建文件,但无法向其中写入数据(读取时数据为空)。下面是我的 JS 代码:

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {
    writeTestList();
}

function writeTestList() {
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystemForWrite, function() { showMsg('Unable to access file system for write'); });
  }

function gotFileSystemForWrite(fileSystem) {
    fileSystem.root.getFile('testList.txt', {create: true, exclusive: false}, gotFileEntryForWrite, function() { showMsg('Unable to access file for write'); });
}

function gotFileEntryForWrite(fileEntry) {
   fileEntry.createWriter(gotFileWriter, function() { showMsg('Unable to create test list'); });
}

function gotFileWriter(writer) {
    writer.onwrite = function(evt) {
      // show a message
      alert('created the test lists');
      readSavedContent();
   };
   writer.onerror = function(evt) {
     alert(JSON.stringify(evt));
   };
   writer.write("raj");
   alert(writer.length);
}

控件总是进入 writer 的 onerror 内部,并在提醒事件 obj 时,我看到一个类型:“error”,错误:“JSON error”。我完全不明白这一点。我正在写入一个 txt 文件,但收到 json 错误。我已将写权限放入 android list 中。此外,我在 config.xml 首选项中启用了 cordova 的存储插件。人们,请帮我解决这个问题..!!

最佳答案

无法在 cordova 3.0 中修复此问题。移至 cordova 2.9,一切正常。

关于javascript - Apache cordova - 无法写入android中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19082010/

相关文章:

php - 在虚拟服务器上运行外部程序

php - 如何访问放置在站点根目录之外的文件?

javascript - jQuery Mobile -> 覆盖 jQuery UI Datepicker -> 布局损坏

javascript - 在同一 Fetch POST API 调用中返回 JSON

django - 如何在 Django 应用程序中使用 SSL(使用 mod_wsgi 和 virtualenv 部署)

iphone - HTML5 Webapp 作为 iPhone 和 Android 上的常规图标或应用程序。

java - 构造函数未定义使用动态 ViewPager

javascript - 创建一个随机数组来比较西蒙说游戏中的用户数组和闪烁

javascript - 谷歌图表 : Data column(s) for axis #0 cannot be of type string

android - 任务 killer 应用与 SupportFragmentManager Backstack