How to create file in Sdcard using phonegap

后端 未结 1 1976
逝去的感伤
逝去的感伤 2021-02-10 04:06

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

相关标签:
1条回答
  • 2021-02-10 04:49
    // 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.

    0 讨论(0)
提交回复
热议问题