从 java 中的 ByteBuffer 获取字节数组 [英] Gets byte array from a ByteBuffer in java
本文介绍了从 java 中的 ByteBuffer 获取字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是从 ByteBuffer 中获取字节的推荐方法吗
Is this the recommended way to get the bytes from the ByteBuffer
ByteBuffer bb =..
byte[] b = new byte[bb.remaining()]
bb.get(b, 0, b.length);
推荐答案
取决于你想做什么.
如果您想要检索剩余的字节(在位置和限制之间),那么您所拥有的将起作用.你也可以这样做:
If what you want is to retrieve the bytes that are remaining (between position and limit), then what you have will work. You could also just do:
ByteBuffer bb =..
byte[] b = new byte[bb.remaining()];
bb.get(b);
这相当于 ByteBuffer javadocs.
which is equivalent as per the ByteBuffer javadocs.
这篇关于从 java 中的 ByteBuffer 获取字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文