package { import flash.display.Sprite; import flash.events.Event; import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream; import flash.net.URLLoader; import flash.net.URLRequest; import flash.system.System; import flash.text.TextField; /** * ... * @author Frost.Yen */ public class Main extends Sprite { private var _t:TextField; public function Main() { System.useCodePage = true;//解决中文乱码问题 _t = new TextField(); _t.autoSize = "left"; this.addChild(_t); readTxt();//方法一(仅限AIR) //loadTxt();//方法二 } private function readTxt():void { var file:File = new File(File.applicationDirectory.nativePath + "/新建文本文档.txt"); var stream:FileStream = new FileStream(); //创建FileStream对象 stream.open(file,FileMode.READ); //使用FileStream对象以只读方式打开File对象 //将文件中的所有信息显示在文本区域中 _t.text = stream.readUTFBytes(stream.bytesAvailable); stream.close(); //关闭FileStream对象 } private function loadTxt():void { var ldr:URLLoader = new URLLoader(); ldr.load(new URLRequest("新建文本文档.txt")); ldr.addEventListener(Event.COMPLETE, onComplete); } private function onComplete(e:Event):void { _t.text = String(e.target.data); } } } 转载于:https://www.cnblogs.com/frost-yen/p/4721714.html