<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="486" height="356"
applicationComplete="onAppInit();" >
<mx:Script><![CDATA[
import mx.events.IndexChangedEvent;
private var file:File;
/**
* 程序初始化
*/
public function onAppInit():void
{
file = new File("f:/a.txt");
var reader:FileStream = new FileStream();
reader.open(file, FileMode.UPDATE);
var len:int = reader.bytesAvailable;
var str:String = reader.readUTFBytes(len);
trace(str.replace(/\r\n/g, "|"));
}
]]>
</mx:Script>
</mx:WindowedApplication>
以上代码是读取一个文本文件,然后把回车换行替换为“|”。