Last active
November 9, 2015 09:58
-
-
Save vintesh/2f755951ed917afc7198 to your computer and use it in GitHub Desktop.
PhoneGap/Cordova File Read - DirectoryEntry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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