bytebuffer 与 byte数组 转化

来源:互联网 发布:狸窝视频编辑软件 编辑:程序博客网 时间:2024/06/05 14:14
更多0
java
ByteBuffer
// 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);
0 1