Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Write to an existing text file

Has any had any experience with this? so far i'm able list the contents of a directory, click a file name and open it's contents in to a textarea but am not able to save the updated content.


— asked September 2nd 2010 by Kelly Redd
  • file
  • filestream
  • filesystem
  • ipad
  • write
1 Comment
  • Figured it out.

    — commented September 3rd 2010 by Kelly Redd

3 Answers

  • Colton, here is how i'm doing it. Hope it helps…

    function fn_save_file(data,path,title) // data to be saved, path to file, name of file
        if(data) // make sure we have something to save
            var file = Titanium.Filesystem.getFile(parent, path + title + '.txt'); // create file object
            if(file.write(data)) // this line does the saving! and if successful does something next
                // do something after saving the file. I use it like a callback function
            if(!file.write(data)) // tell user if save is unsuccessful
                var save_error = Ti.UI.createAlertDialog({
                    title: 'SAVE ERROR',
                    message: 'Could not save file',
                    buttonNames: ['OK']
    — answered September 26th 2010 by Kelly Redd
  • Checkout the Mobile API's File Object for this. And also, the Kitchensink and Titanium Sandbox have examples of using this.
    What you're looking for though is the Method or Property (i forget which) that specifies what kind of FileMode that you're opening the file as. Whether it's Binary, Append, Read, Write, etc…

    — answered September 24th 2010 by Kevin Johnson
  • Kelly, from your Comment on the OP it seems you have figured this out? Could you explain how to do it, for people (like me…) who would like to know? :)

    — answered September 24th 2010 by Colton Arabsky
    1 Comment
    • Sure thing! I'm on my way out of town but will post when I get back.

      — commented September 24th 2010 by Kelly Redd
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.