When you’re developing an AIR application it’s useful to be able to quickly save information to a file. Especially when it comes to things like tracking the memory usage of an application over a period of time.
This doesn’t require anything fancy. Here’s an example of a simple log() method that either writes or appends to a file called “Output.log” on the desktop:
|
public function log (text : String, clear : Boolean = false) : void { var file : File = File.desktopDirectory.resolvePath (“Output.log”); var fileMode : String = (clear ? FileMode.WRITE : FileMode.APPEND); var fileStream : FileStream = new FileStream (); fileStream.open (file, fileMode); fileStream.writeMultiByte (text + “\n”, File.systemCharset); fileStream.close (); } |
It’s easy to modify an example like this to allow for different file names and paths. It’s also easy to append timestamps or other identifying information.
In short, quick and simple.

1 comment
Comments feed for this article
October 17, 2008 at 7:21 am
localToGlobal » Blog Archive » news review -> 42th week of 2008
[...] > An Easy Way To Append To a Log File in AIR « Miscellanea [...]