- public static void main(String[] args) {
- byte[] b = new byte[Integer.SIZE / Byte.SIZE];// 4字节存int型正好
- ByteBuffer bb = ByteBuffer.wrap(b);// 包装一下
- bb.putInt(-1270);//put一个整数
- System.out.println(bb.order().toString());// 打印jvm默认的字节序
- System.out.println(bb.getInt(0));// 打印咱刚放进去的整数
- bb.order(ByteOrder.nativeOrder());// 修改字节序为本地操作环境的字节序一致
- System.out.println(bb.order().toString());// 打印修改后的字节序
- System.out.println(bb.getInt(0));// 发现int的值变了,原因就是改变了字节序
- }
- //该片段来自于http://www.codesnippet.cn/detail/2010201410676.html
来源: http://www.codesnippet.cn/detail/2010201410676.html