Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

I tried this, it didn't work. Another question how can I read a file with path.
code
function saveTheFile(filename, content) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
fs.root.getFile(filename, { create: true }, function (fileEntry) {

Code: Select all

                 fileEntry.createWriter(function (fileWriter) { 

    fileWriter.onwriteend = function (e) { 

                     }; 

  fileWriter.onerror = function (e) { 
                         alert('Error occured: ' + e.toString() + "\n File couldn't saved"); 
                     }; 

                     var contentBlob = new Blob([content], { type: 'text/plain' }); 

                     fileWriter.write(contentBlob); 

                 }, handleError); 

             }, handleError); 
         } 
     ); 

}
saveTheFile(bg.txt,"aaaaa");
/code

Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

I fixed using

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

fs.root.getFile("GREN/background.css",{create: true}, function(DatFile){

DatFile.createWriter(function(DatContent) {

var blob = new Blob(["Lorem Ipsum"],{type: "text/plain"});

DatContent.write(blob);

Code: Select all

 }); 

});

Code: Select all

         } 
     ); 

/code

Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

How to read a file?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

write/read a file?

Hi Elvin -

This question relates to Cordova APIs the best place is to check their documentation on git: https://github.com/apache/cordova-plu...

-- and also here is a good article: http://www.html5rocks.com/en/tutorial...

Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

Hello I read already :) but the code I use it didn't work at all can u help me fix it please?

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

fs.root.getFile('GREN/background.css', {}, function(fileEntry) {

Code: Select all

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

    reader.onloadend = function(e) { 

     $scope.file = this.result; 

    }; 

    reader.readAsText(file); 
 }, errorHandler); 

}, errorHandler);
});
/code

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

write/read a file?

It's hard to say for sure without knowing your code context here.

Could you explain with more details what you are trying to implement in application, what builder version you are using and on what device platform?

Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

I tested on my phone with android,5.0

Elvin Chu
Posts: 0
Joined: Sat Apr 11, 2015 2:52 pm

write/read a file?

It didn't work at all

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

write/read a file?

Where exactly in your app you using this code?

Return to “Issues”