Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create file in Sdcard using phonegap

How to create file and save file in Android Sdcard Using phonegap ?

like image 485
Piyush Avatar asked Jan 17 '13 03:01

Piyush


1 Answers

// 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.

like image 70
SHANK Avatar answered Nov 14 '22 23:11

SHANK