Buffer class provides 'isReadOnly()' method, to check
whether the buffer is read only or not.
Test.java
package com.sample.nio; import java.nio.ByteBuffer; public class Test { public static void main(String args[]) throws Exception { ByteBuffer byteBuffer1 = ByteBuffer.allocate(5); ByteBuffer byteBuffer2 = byteBuffer1.asReadOnlyBuffer(); System.out.println("is byteBuffer1 readOnly ? : " + byteBuffer1.isReadOnly()); System.out.println("is byteBuffer2 readOnly ? : " + byteBuffer2.isReadOnly()); } }
Output
is byteBuffer1 readOnly ? : false
is byteBuffer2 readOnly ? : true
is byteBuffer2 readOnly ? : true
No comments:
Post a Comment