如何使用phonegap在Sdcard中创建文件 [英] How to create file in Sdcard using phonegap
本文介绍了如何使用phonegap在Sdcard中创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用phonegap在Android Sdcard中创建文件和保存文件
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);
}
$ b $ p
这里创建文件编写器方法提供了文件系统的句柄。在成功函数中,我们得到名为file_name.txt的文件,如果存在,则打开它,否则创建它。
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.
这篇关于如何使用phonegap在Sdcard中创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文