<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:skins="graphite.skins.*"
width="800" height="600">
<fx: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.readMultiByte(fs.bytesAvailable, "gb2312"); fs.close();
txtContent.text = fs.readMultiByte(fs.bytesAvailable, "utf-8"); 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();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- ( 、 ) -->
</fx:Declarations>
<s:TextInput id="txtPath" x="10" y="10" width="321"/>
<s:Button id="btnOpen" x="339" y="10" label="Open" click="onOpen()"/>
<s:TextArea id="txtContent" x="10" y="40" width="394" height="276"/>
<s:Button x="339" y="324" label="Save" click="Save()"/>
</s:WindowedApplication>