<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" width="429" height="376">
<mx:Script>
<![CDATA[
import mx.messaging.AbstractConsumer;

private function init():void{

}

private function onOpen():void
{
var file:File = new File();
file.browseForOpen("Select a text file",[new FileFilter("text file","*.txt")]);
file.addEventListener(Event.SELECT,onFileSelect);
}

private function onFileSelect(e:Event):void{
var fs:FileStream = new FileStream();
txtPath.text = File(e.target).nativePath;
fs.open(File(e.target),FileMode.READ);
txtContent.text = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
}

private function Save():void{
var fs:FileStream = new FileStream();
fs.open(new File(txtPath.text),FileMode.WRITE);
fs.writeUTFBytes(txtContent.text);
fs.close();
}
]]>
</mx:Script>
<mx:TextInput id="txtPath" x="10" y="10" width="321"/>
<mx:Button id="btnOpen" x="339" y="10" label="Open" click="onOpen()"/>
<mx:TextArea id="txtContent" x="10" y="40" width="394" height="276"/>
<mx:Button x="339" y="324" label="Save" click="Save()"/>
</mx:WindowedApplication>

虽然读写过程都正常,但遇到中文字符时就会出现乱码,不知何因.