如何使用Phonegap在SD卡中创建文件

5
如何在安卓SD卡上使用PhoneGap创建文件和保存文件?
1个回答

7
// 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);
}

在这里创建文件写入方法提供了对文件系统的句柄。在成功函数中,如果存在名为'file_name.txt'的文件,则打开它,否则创建它。


3
这个操作不会将文件保存到SD卡中,而是保存在手机内存中。如何将文件保存到SD卡中? - Ashok Shah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接