4). 最简单的方式是,使用我编写的LEDataInputStream, LEDataOutputStream 和LERandomaccessFile模拟 DataInputStream, DataOutputStream and RandomAccessFile ,它们使用的是little-endian字节流。 You can read about LEDataStream. You can download the code and source free. You can get help from the File I/O Amanuensis to show you how to use the classes. Just tell it you have little-endian binary data.
2.你可能甚至不会有任何问题。 从C来的许多Java新手可能会认为需要考虑它们所依靠的平台内部所使用的是big还是little问题。在Java中这不是一个问题。进一步,不借助于本地类,你无法知道它们是如何存储的。Java has no strUCt I/O and no unions or any of the other endian-sensitive language constructs.
仅在与遗留的C/C++应用程序通讯时需要考虑endian问题。下列代码在big or little endian机器上都将产生同样的结果:
// take 16-bit short apart into two 8-bit bytes. short x = 0xabcd; byte high = (byte) (x >>> 8); byte low = (byte) x;/* cast implies & 0xff */ System.out.PRintln ("x=" + x + " high=" + high + " low=" + low );
3.读Little-Endian Binary Files The most common problem is dealing with files stored in little-endian format.
I had to implement routines parallel to those in java.io.DataInputStream which reads raw binary, in my LEDataInputStream and LEDataOutputStream classes. Don't confuse this with the io.DataInput human-readable character-based file-interchange format.
If you wanted to do it yourself, without the overhead of the full LEDataInputStream and LEDataOutputStream classes, here is the basic technique:
Presuming your integers are in 2's complement little-endian format, shorts are pretty easy to handle: