设置ByteBuffer的字节顺序
import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { /* n o w j a v a . c o m */ public static void main(String[] args) throws Exception { // Obtain a ByteBuffer; see also Creating a ByteBuffer ByteBuffer buf = ByteBuffer.allocate(10); // Get default byte ordering ByteOrder order = buf.order(); // ByteOrder.BIG_ENDIAN // Put a multibyte value buf.putShort(0, (short) 123);// 来自 时代Java公众号 buf.get(0); // 0 buf.get(1); // 123 // Set to little endian buf.order(ByteOrder.LITTLE_ENDIAN);