Call theFileStream.open()orFileStream.openAsync()method, passing in theFileobject as thefileparameter and passing an appropriate file mode as thefileModeparameter. For example:
Close the file, using theFileStream.close()method. For example:
stream.close();
Steps 3, 4, and 5 are described in more detail the sections that follow. First, here is a sample of code for reading UTF-8 text from a file synchronously:
var file:File = File.appStorageDirectory; file = file.resolve("settings.xml"); var stream:FileStream = new FileStream(); stream.open(file, FileMode.READ); var data:String = stream.readUTFBytes(stream. bytesAvailable); stream.close();
Here is some code that reads the same data asynchronously:
var file:File = File.appStorageDirectory; file = file.resolve("settings.xml"); var stream:FileStream = new FileStream(); stream.openAsync(file, FileMode.READ); stream.addEventListener(Event.COMPLETE, readData); var data:String;
private function readData(event:Event):void { data = stream.readUTFBytes(stream.bytesAvailable); stream.close(); }