java ByteBuffer和byte 数组相互转换,bytebufferbyte,// Create a
分享于 点击 48364 次 点评:61
java ByteBuffer和byte 数组相互转换,bytebufferbyte,// Create a
// Create a byte arraybyte[] bytes = new byte[10];// Wrap a byte array into a bufferByteBuffer buf = ByteBuffer.wrap(bytes);// Retrieve bytes between the position and limit// (see Putting Bytes into a ByteBuffer)bytes = new byte[buf.remaining()];// transfer bytes from this buffer into the given destination arraybuf.get(bytes, 0, bytes.length);// Retrieve all bytes in the bufferbuf.clear();bytes = new byte[buf.capacity()];// transfer bytes from this buffer into the given destination arraybuf.get(bytes, 0, bytes.length);
用户点评