How to Create a txt File using Cordova

Asked

Viewed 72 times

0

I have this code here

// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
//
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
    writer.onwriteend = function(evt) {
        console.log("contents of file now 'some sample text'");
        writer.truncate(11);  
        writer.onwriteend = function(evt) {
            console.log("contents of file now 'some sample'");
            writer.seek(4);
            writer.write(" different text");
            writer.onwriteend = function(evt){
                console.log("contents of file now 'some different text'");
            }
        };
    };
    writer.write("some sample text");
}

function fail(error) {
    console.log(error.code);
}

but does not create the file, which is the error?

  • Does the program return an error? You have write permissions in the program’s Raiza folder?

  • Problem solved !

  • And that problem would be?

  • No, he created the file but the file directory was not accessible , I had to change the directory.

  • No, he created the file but the file directory was not accessible , I had to change the directory.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.