Save File in Adobe Flex -AIR

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”onCreate(event)”>
<mx:Script>
<![CDATA[
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
private
function onCreate(e:Event):
void
{

var file:File = File.desktopDirectory; //Set the Directory location to Desktop
file = file.resolvePath(
“test.txt); //File Name
var
fileStream:FileStream = new
FileStream();   // Create new FileStream to Perform Read or Write
fileStream.open(file, FileMode.WRITE); // Open file in WRITE Mode
fileStream.writeUTFBytes(
“Hello World”); //Write Hello World into test.txt
fileStream.close(); //Close the File Stream
}

]]>
</mx:Script>
</mx:WindowedApplication>


This code creates a file named test.txt with content “Hello World” in desktop folder.

The desktopDirectory property provides a way to reference the desktop directory that works across platforms. If you set a File object to reference the desktop directory using the nativePath or url property, it will only work on the platform for which that path is valid Similarly documentDirectory /applicationStorageDirectory /applicationDirectory can be used to represent the folder.

var file:File = new File();
file = file.resolvePath(
“c:\\test.txt”);

This will work in windows platform and stores file in user mentioned location.