I'm using cordova-plugin-file to write a text file. I can get the plugin to populate a <div>
on a modal popup. This snippet works perfectly:
function readFile6(fileName){
var str = '';
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir){
dir.getFile(fileName, {create: false}, function(fileEntry){
fileEntry.file(function(file){
var reader = new FileReader();
reader.onloadend = function (evt) {
$(".accordine").html(evt.target.result);
};
reader.readAsText(file);
}, function(error){
alert("Error: " + error.code);
});
}, function(error){
alert("Error: " + error.code);
});
}, function(){
alert("Error");
});
Problem is, I need the content of the file to be returned to the calling function so I can manipulate the data before it is displayed.
I read every tutorial/sample I can find, but none of the examples shows how to do anything with the contents except populate a div
or show in console.log()
.
How can I get the text file's contents as a return value?