Flex:读取字节数组
我使用以下命令将文件上传到 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
' 而不是字符串的其余部分。
知道如何成功读取整个 txt 文件吗?
I use the following to upload a file to 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();
}
And my file looks like this:
Here is the original file: http://sesija.com/up/1.txt
I need to read the uploaded file and parse it. The problem is that in my e.currentTarget.data.toString();
I get only '1
' and not the rest of the String.
Any idea on how to successfully read this entire txt file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
data 属性是ByteArray。不要使用 toString 方法(显然将 NULL 字节视为字符串结尾),而是使用 ByteArray 类的特定读取方法,例如 readByte、readInt > 等。
您可能想阅读使用字节数组
The data property is a ByteArray. Instead of using the
toString
method (which apparently treats NULL byte as end of string), use specific read methods of the ByteArray class likereadByte
,readInt
etc.You might want to read Working with byte arrays