Phonegap cordova-plugin-file没有创建任何文件

问题描述 投票:0回答:1

phonegap cordova-plugin-file在我的phonegap上不起作用。它不会创建任何txt文件。

我已经尝试使用官方参考中提供的代码。 https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#persistent

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

function onErrorCreateFile() {
console.log("Create file fail...");}

function onErrorLoadFs() {
console.log("File system fail...");
}

function onErrorReadFile() {
console.log("Read File fail...");
}

function displayFileData(data){
// alert(data);
}

function readFile(fileEntry) {

fileEntry.file(function (file) {
var reader = new FileReader();

reader.onloadend = function() {
console.log("Successful file read: " + this.result);
displayFileData(fileEntry.fullPath + ": " + this.result);
};

reader.readAsText(file);

}, onErrorReadFile);
}

function createFile(dirEntry, fileName, isAppend) {
// Creates a new file or returns the file if it already exists.
dirEntry.getFile(fileName, {create: true, exclusive: false}, function(fileEntry) {

writeFile(fileEntry, null, isAppend);

}, onErrorCreateFile);

}

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {

console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {

console.log("fileEntry is file?" + fileEntry.isFile.toString());
// fileEntry.name == 'someFile.txt'
// fileEntry.fullPath == '/someFile.txt'
writeFile(fileEntry, null);

}, onErrorCreateFile);

}, onErrorLoadFs);

}

将创建预期的newPersistentFile.txt文件。但在任何目录下均未创建任何内容。

javascript phonegap-plugins phonegap-build phonegap
1个回答
0
投票

您解决了这个问题吗?我遇到了同样的问题,如果发现了问题,请分享解决方案。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.