代码之家  ›  专栏  ›  技术社区  ›  Adnan

Flex:读bytearray

  •  3
  • Adnan  · 技术社区  · 15 年前

    我使用以下方法将文件上载到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 “而不是绳子的其余部分。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Amarghosh    15 年前

    这个 data 财产是一种财产 ByteArray . 而不是使用 toString 方法(显然将空字节视为字符串的结尾),使用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

    推荐文章