集册 Java实例教程 创建一个ByteBuffer

创建一个ByteBuffer

欢马劈雪     最近更新时间:2020-01-02 10:19:05

431
创建一个ByteBuffer

import java.nio.ByteBuffer;
//来 自 N o w J a v a . c o m - 时代Java

public class Main {

  public void m() {

    // Create a ByteBuffer using a byte array

    byte[] bytes = new byte[10];

    ByteBuffer buf = ByteBuffer.wrap(bytes);


    // Create a non-direct ByteBuffer with a 10 byte capacity

    buf = ByteBuffer.allocate(10);


    // Create a direct (memory-mapped) ByteBuffer with a 10 byte capacity.

    buf = ByteBuffer.allocateDirect(10);/**nowjava - 时代Java**/


  }

}