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 file

I would like to write a text file (.txt) , in which I use the following code:

var file1 = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'test.txt');
var cont;
if (file1.exists()) {
    cont = file1.read();
    alert("File exists");
} else {
    file1.write('Hello World...');
    cont = file1.read();
    Ti.API.info("File save");
    alert("File1 : "+cont.text);

This code doesn't cause me any problem in the simulator, but when I put it in th Iphone it doesn't work.

Can somebody help me please?

— asked April 14th 2010 by Jaime Ortiz
  • iphone
1 Comment
  • You have to use


    instead of


    Because resourceDirectory is only working on simulator

    — commented July 5th 2011 by Jiale He

1 Answer

  • I was pulling my hair out with the filesystem earlier this week. The simulator was giving me one thing and I couldn't tell what I was getting on my iPhone end.

    In your code have an alert that pops up and telling you if the var file1 is writable. This way you know for sure. I had to use the temp directory.

    — answered April 15th 2010 by Ryan Gartin
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.