Skip to content

Instantly share code, notes, and snippets.

@vintesh
Last active November 9, 2015 09:58
Show Gist options
  • Save vintesh/2f755951ed917afc7198 to your computer and use it in GitHub Desktop.
Save vintesh/2f755951ed917afc7198 to your computer and use it in GitHub Desktop.
PhoneGap/Cordova File Read - DirectoryEntry
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem) {
window.resolveLocalFileSystemURL(DIR_PATH,
function(directoryEntry) {
console.log('Directory Entry Log - ', directoryEntry);
directoryEntry.getFile(FILE_NAME, { create: true, exclusive: false },
function(fileEntry) {
fileEntry.file(
function(file){
console.log('File Object Retrieved is - ', file);
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log('File Content - ', reader.result);
if(evt.target.result) {
console.log('Event - ', evt);
} else {
console.log('Error. - ', evt);
}
};
reader.readAsText(file);
},
function(error) {
console.log('File Read cannot complete on File System - ', error);
}
);
}, function(error) {
console.log('Reader cannot read from the File System - ', error);
}
);
}, function(error) {
console.log('Error - ', error);
}
);
},
function(error) {
console.log('FileEntry Cannot be retrieved - ', error);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment