2

I am creating an application with TideSDK and will need to create files for the projects. However I cannot find any way to create a file. On the API docs I saw the function createDirectory(). Will that create a file? If not, what will?

Or am I going about this the wrong way? Should I be storing the data for the projects in an SQLite database? I'm lost, please help.

PS. If anyone knows a good tutorial on the Filesystem in TideSDK that would be extremely helpful.

tshepang
  • 12,111
  • 21
  • 91
  • 136
KFox
  • 1,166
  • 3
  • 10
  • 35

2 Answers2

5
//Doesnt have to exist yet.
var fileHandle = Ti.Filesystem.getFile('/path/to/file');
fileHandle.write('data');

You can see a real-world usage example here:

https://github.com/meeech/Shopify-Theme-Tool/blob/tidesdk-1.3/Resources/js/io.js#L101-L119

meeech
  • 1,396
  • 13
  • 21
  • This is deprecated! Reason: The method has been superseded by Filestream.write() version: 1.1.0 – dude Jun 16 '15 at 14:03
0

The answer from @meeech is deprecated because the method has been superseded by Filestream.write() version: 1.1.0. This should now be done with:

var tmpFile = Ti.Filesystem.createTempFile();
var stream = Ti.Filesystem.getFileStream(tmpFile);
stream.open(Ti.Filesystem.MODE_WRITE);
stream.write("YOUR DATA");
stream.close();
dude
  • 5,678
  • 11
  • 54
  • 81