Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
To write data to files in either persistent or temporary storage, an application uses a FileWriter object. To begin the process, the application must first get access to a file object representing the file using the getFile method, as shown in the following example:
theFileSystem.root.getFile('appdata1.txt', {create : true},
onGetFileSuccess, onFileError);
After the call to getFile, the onGetFileSuccess function is executed and passed the file object that will be used to create the FileWriter, as shown in the following example:
function onGetFileSuccess(theFile) {
theFile.createWriter(onCreateWriterSuccess, onFileError);
}
Once again, we have another callback to wait for; once the FileWriter has been created, the callback function is executed, and the actual file writing can happen, as illustrated in the following example: