我使用以下文件将文件上传到Flex:
private var filer:FileReference;
protected function button1_clickHandler(event:MouseEvent):void
{
var fd:String = "Files (*)";
var fe:String = "*";
var ff:FileFilter = new FileFilter(fd, fe);
filer = new FileReference();
filer.addEventListener(Event.SELECT, onFileSelect);
filer.browse(new Array(ff));
filer.addEventListener(Event.COMPLETE,
function (e:Event):void {
e.currentTarget.data.toString();
}
);
}
private function onFileSelect(e:Event):void {
filer.load();
}
我的文件如下所示:
这是原始文件:http://sesija.com/up/1.txt
我需要阅读上传的文件并进行解析。问题是在我的
e.currentTarget.data.toString();
中,我只得到'1
',而没有得到其余的String。关于如何成功读取整个txt文件的任何想法吗?
最佳答案
data属性是ByteArray。代替使用toString
方法(显然将NULL字节视为字符串的结尾),而应使用ByteArray类的特定读取方法,例如readByte
,readInt
等。
var array:Array = [];
var ba:ByteArray = e.currentTarget.data as ByteArray;
while(ba.bytesAvailable != 0){
array.push(ba.readByte());
}
trace(array.join(", "));
您可能需要阅读Working with byte arrays
关于apache-flex - Flex:读取字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3802588/