Flex:读取字节数组

发布于 2024-09-24 17:56:51 字数 1063 浏览 0 评论 0原文

我使用以下命令将文件上传到 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(); 
        }

我的文件如下所示: alt text

这是原始文件: 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:
alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-10-01 17:56:51

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(", "));

您可能想阅读使用字节数组

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 like readByte, readInt etc.

var array:Array = [];
var ba:ByteArray = e.currentTarget.data as ByteArray;
while(ba.bytesAvailable != 0){
    array.push(ba.readByte());
}
trace(array.join(", "));

You might want to read Working with byte arrays

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文