javascript - How can I use the File Writer object in steroids js to write to the local JSON file? -


i'm building application steroids js , i'd able overwrite contents of local json file app gets data upon app's launch. think file writer object need accomplish task i'm not quite of i'm not quite of how can write local json file under www/myapp.json it.

information on file writer : http://docs.appgyver.com/en/edge/cordova_file_file.md.html#filewriter

details

the filewriter object offers way write utf-8 encoded files device file system. applications respond writestart, progress, write, writeend, error, , abort events.

each filewriter corresponds single file, data can written many times. filewriter maintains file's position , length attributes, allow app seek , write anywhere in file. default, filewriter writes beginning of file, overwriting existing data. set optional append boolean true in filewriter's constructor write end of file.

text data supported platforms listed below. text encoded utf-8 before being written filesystem. platforms support binary data, can passed in either arraybuffer or blob.

<!doctype html> <html> <head> <title>filereader example</title>  <script type="text/javascript" charset="utf-8" src="cordova-1.8.0.js"></script> <script type="text/javascript" charset="utf-8">  // wait cordova load // function onload() {     document.addeventlistener("deviceready", ondeviceready, false); }  // cordova ready // function ondeviceready() {     window.requestfilesystem(localfilesystem.persistent, 0, gotfs, fail); }  function gotfs(filesystem) {     filesystem.root.getfile("readme.txt", null, gotfileentry, fail); }  function gotfileentry(fileentry) {     fileentry.file(gotfile, fail); }  function gotfile(file){     readdataurl(file);     readastext(file); }  function readdataurl(file) {     var reader = new filereader();     reader.onloadend = function(evt) {         console.log("read data url");         console.log(evt.target.result);     };     reader.readasdataurl(file); }  function readastext(file) {     var reader = new filereader();     reader.onloadend = function(evt) {         console.log("read text");         console.log(evt.target.result);     };     reader.readastext(file); }  function fail(evt) {     console.log(evt.target.error.code); }  </script> </head> <body> <h1>example</h1> <p>read file</p> </body> </html> 


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -