获取从ByteBuffer中的Java字节数组 [英] Gets byte array from a ByteBuffer in java

查看:979
本文介绍了获取从ByteBuffer中的Java字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是推荐的方式来获得ByteBuffer的

字节

 的ByteBuffer BB = ..字节[] B =新的字节[bb.remaining()]
bb.get(B,0,b.length个);


解决方案

取决于你想要做的事。

如果你想要的是可以检索剩余的(位置和限制之间)的字节数,你有那么什么工作。你也可以只做到:

 的ByteBuffer BB = ..字节[] B =新的字节[bb.remaining()]
bb.get(二);

这相当于为每<一href=\"http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html#get%28byte%5B%5D%29\">ByteBuffer的javadoc。

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);

解决方案

Depends what you want to do.

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);

which is equivalent as per the ByteBuffer javadocs.

这篇关于获取从ByteBuffer中的Java字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆