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
    var fileMode : String = (clear ? FileMode.WRITE :

    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. 🙂