可以使用order()
类java.nio.ShortBuffer中的方法获得缓冲区的字节顺序。此方法不需要任何参数,它返回缓冲区的字节顺序。
演示此的程序如下所示-
import java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ShortBuffer buffer = ShortBuffer.allocate(n); buffer.put((short)12); buffer.put((short)91); buffer.put((short)25); buffer.put((short)18); buffer.put((short)30); System.out.println("The byte order of the buffer is: " + buffer.order()); } catch (IllegalArgumentException e) { System.out.println("Error!!! IllegalArgumentException"); } catch (ReadOnlyBufferException e) { System.out.println("Error!!! ReadOnlyBufferException"); } } }
上面程序的输出如下-
输出结果
The byte order of the buffer is: LITTLE_ENDIAN