You can see the full example here:
http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#FileWriter
This line creates a file if it does not exist:
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
Supported Platforms
Android BlackBerry WebWorks (OS 5.0 and higher) iOS Windows Phone 7 (Mango)
I do not know about others, but in iOS, the document is created in / var / mobile / Application / YOU _APP / Documents
[THE CODE]
<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>
Hope this helps
source share