Java ByteBuffer get read only byte buffer
import java.nio.ByteBuffer; public class Main { public static void main(String[] args) { // Create a buffer that is read-write by default ByteBuffer bb = ByteBuffer.allocate(1024); boolean readOnly = bb.isReadOnly(); // Assigns false to readOnly System.out.println(readOnly); // Get a read-only buffer ByteBuffer bbReadOnly = bb.asReadOnlyBuffer(); readOnly = bbReadOnly.isReadOnly(); // Assigns true to readOnly System.out.println(readOnly); }/*from w ww . j a v a2 s .c o m*/ }