BufferString bs = new BufferString("HelloWorld");
byte[] b = bs.toString().getBytes();

解决方案 »

  1.   

    bufferstring让你处理string时减小开销
      

  2.   

    请看清楚,不是StringBuffer.而是ByteBuffer.
    java.nio.ByteBuffer   (非阻塞IO操作API中的一个类)
      

  3.   

    竟然没人知道?
    我想把ByteBuffer好像StringBuffer那样用,因为直接用BYTE[]需要先分配大小,然后以后又要把它重新构造成适合大小的BYTE[].
    如果可以用ByteBuffer构造就好了~
      

  4.   

    array
    public final byte[] array()Returns the byte array that backs this buffer  (optional operation). 
    Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa. Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array. 
    Returns:
    The array that backs this buffer 
    Throws: 
    ReadOnlyBufferException - If this buffer is backed by an array but is read-only 
    UnsupportedOperationException - If this buffer is not backed by an accessible array