打开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();
要正确处理输入的字节顺序,您需要准确地知道文件中存储的内容以及以什么顺序(所谓的协议或格式).