如何将liitle Endian二进制文件转换成大Endian二进制文件.我有一个用C编写的二进制二进制文件,我用
Java中的DataInputStream读取这个文件,读入大印度格式.i也看过ByteBuffer类,但是不知道如何使用它来获得我想要的结果.请帮忙.
非常感谢
解决方法
打开NIO FileChannel:
- FileInputStream fs = new FileInputStream("myfile.bin");
- FileChannel fc = fs.getChannel();
设置ByteBuffer endianness(由[get | put]使用)Int(),[get | put] Long(),[get | put] Short(),[get | put] Double()
- ByteBuffer buf = ByteBuffer.allocate(0x10000);
- buf.order(ByteOrder.LITTLE_ENDIAN); // or ByteOrder.BIG_ENDIAN
从FileChannel读取到ByteBuffer
- fc.read(buf);
- buf.flip();
- // here you take data from the buffer by either of getShort(),getInt(),getLong(),getDouble(),or get(byte[],offset,len)
- buf.compact();