How to create file and save file in Android Sdcard Using phonegap ?
// create a file writer object
function CreateFileWriter()
{
// request the file system object
window.requestFileSystem( LocalFileSystem.PERSISTENT, 0, OnFileSystemSuccess,fail);
}
function OnFileSystemSuccess( pFileSystemObj )
{
console.log( pFileSystemObj.name );
console.log( pFileSystemObj.root.name );
pFileSystemObj.root.getFile( "file_name.txt", {create: true, exclusive: false}, OnFileGetSuccess, fail);
}
function OnFileGetSuccess( pFileEntryObj )
{
pFileEntryObj.createWriter( function(pWriterObj){
gWriterObj = pWriterObj;
}, fail );
}
function fail(evt)
{
console.log(evt.target.error.code);
}
Here create file writer method provides a handle to the file system. In the success function, we get the file called, 'file_name.txt', if exists it opens up otherwise creates it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With