Creating a ByteBuffer - Java File Path IO

Java examples for File Path IO:ByteBuffer

Description

Creating a ByteBuffer

Demo Code

import java.nio.ByteBuffer;

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

  }/* www  . j a v  a 2 s. c o  m*/
}

Related Tutorials