您可以在此处查看完整示例:
http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#FileWriter
如果文件不存在,则此行创建文件:
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
支持的平台
Android BlackBerry WebWorks(OS 5.0 及更高版本) iOS Windows Phone 7(Mango)
我不知道还有其他人,但在 iOS 中,该文档是在 /var/mobile/Application/YOU_APP/Documents 中创建的
[代码]
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write("some sample text");
writer.abort();
// contents of file now 'some different text'
}
function fail(error) {
console.log("error : "+error.code);
}
</script>
希望能帮助到你