首页javanio_bufferJava I/O - 如何设置ByteBuffer的限制

Java I/O - 如何设置ByteBuffer的限制

我们想知道如何设置ByteBuffer的限制。
  


import java.nio.ByteBuffer;

public class Main {
  public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocateDirect(10);
    buf.limit(7); // remaining=1
  }
}