【发布时间】:2018-02-19 21:23:22
【问题描述】:
我正在尝试使用 Cordova 写入 Android 平板电脑的外部存储(虚拟 SD)。事实上,我正在尝试访问由“bitwebserver”(Android 的 LAMP)创建的“www”目录。
我有以下代码
但我无法创建文件,我得到 5 或 9 错误代码。
我在这里缺少什么?
谢谢!
<script>
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// We're ready
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fail);
}
function gotFileSystem(fileSystem) {
fileSystem.root.getFile(cordova.file.externalRootDirectory + "/www/test.txt", {
create: true,
exclusive: false
}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function (evt) {
console.log("contents of file now 'some sample text'");
writer.truncate(11);
writer.onwriteend = function (evt) {
console.log("contents of file now 'some sample'");
writer.seek(4);
writer.write(" different text");
writer.onwriteend = function (evt) {
console.log("contents of file now 'some different text'");
}
};
};
writer.write("some sample text");
}
function fail(error) {
console.log(error.code);
console.log(error);
}
</script>
【问题讨论】:
标签: android cordova cordova-plugins