Created
December 11, 2010 00:59
-
-
Save cauld/737045 to your computer and use it in GitHub Desktop.
Demonstrates basic filesystem CRUD operations with Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dataToWrite = {"en_us":{"foo":"bar"}}; | |
| //NOTE: remember to use applicationDataDirectory for writes | |
| var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mydir'); | |
| newDir.createDirectory(); | |
| Ti.API.info('Path to newdir: ' + newDir.nativePath); | |
| var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'newfile.json'); | |
| //Stringify the JavaScript object we created earlier and write it out to the new file | |
| newFile.write(JSON.stringify(dataToWrite)); | |
| var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'newfile.json'); | |
| var resources = JSON.parse(newFile.read().text); | |
| resources.en_us.foo = 'baz'; //bar becomes baz | |
| newFile.write(JSON.stringify(resources)); | |
| //We already have references to the file and directory objects. | |
| //We just need to call their cooresponding delete methods. | |
| newFile.deleteFile(); | |
| newDir.deleteDirectory(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment