BinaryReader是用来操作二进制文件的
如果楼主的是文本文件,建议使用FileStream

解决方案 »

  1.   

    我用FLASH生成的就是2进制文件,用16进制编辑器打开看过,一个包含abcd字符串的文件,按Little Endian保存,结果是04 00 61 62 63 64,然后用C#读取出来就变成"\0abcd"了,原因就是MSDN里说的那样,ReadString()默认的是字符串长度只占7位,而FLASH生成的时候长度有16位
      

  2.   

    上面打错了,读出来的是"\0abc"
      

  3.   

    我用BinaryWriter写入了一下,abcd是04 61 62 63 64,所以如果你能写入一个字节的长度,或许就对了。但是长度并不是总是占一个字节,我写入了1000个a,前面的长度是E807
      

  4.   

    二进制 读出来都先放到 byte[]里面
      

  5.   

    可能是你使用的方法有问题
    我不知道flash的方法是什么作用你需要看一下你的文件内容是什么 如果是标准的字符如(abcdefg)
    那么你需要使用 streamreader如果是二进制流才需要使用BinaryReader,文件存的是byte[]才用它
      

  6.   

    刚又试了下,用.net的BinaryWriter的Write()写一个string,string的内容是255个a,写到文件里字符串长度前缀变成了FF01(10进制511),而同样的用Flash写进去,长度前缀为FF00
    看来还是两边读写格式不匹配,估计只能自己重新写个读字符串的函数了
      

  7.   

    ConvertToBigEndian(byte[] buffer, int startIndex, int bytesToConvert)
    {
    long ret = 0;
    for (int i=0; i < bytesToConvert; i++)
    {
    ret = unchecked((ret << 8) | buffer[startIndex+i]);
    }
    return ret;
    }
    把一个byte[]转换成BigEndian。
    第一个参数就是要转换的Byte[],第二个参数是从那一位开始转换,第三个参数是转换多少位
      

  8.   

    还有,读Flash文件里的所有内容(不光是字符串)都要自己写单独的Read方法。
      

  9.   

    恩,楼上说的对,FLASH写2进制文件默认是按Big Endian编码的,除非写的时候手动设置下参数,改成Little Endian,不然的话就只能在读的时候进行转换了
      

  10.   

    ”FLASH写2进制文件默认按BigEndian编码”,这句话可能不完全准确。SWF Specification里有这么一段话:
    The SWF file format uses 8-bit, 16-bit, 32-bit, 64-bit, signed, and unsigned integer types. All
    integer values are stored in the SWF file by using little-endian byte order: the least significant
    byte is stored first, and the most significant byte is stored last, in the same way as the Intel x86
    architecture. The bit order within bytes in the SWF file format is big-endian: the most
    significant bit is stored first, and the least significant bit is stored last.
      

  11.   

    这只是说在SWF的文件里吧,如果我在FLASH AIR工程中用FILESTREAM的WriteInt写,是用BIG ENDIAN