Java CharBuffer.read(CharBuffer target)
Syntax
CharBuffer.read(CharBuffer target) has the following syntax.
public int read(CharBuffer target) throws IOException
Example
In the following code shows how to use CharBuffer.read(CharBuffer target) method.
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Arrays;
//w w w.j av a 2 s . c o m
public class Main {
public static void main(String[] args) throws IOException {
CharBuffer cb1 = CharBuffer.allocate(20);
cb1.append("java2s.com");
cb1.rewind();
System.out.println(Arrays.toString(cb1.array()));
CharBuffer cb2 = CharBuffer.allocate(50);
cb2.read(cb1);
System.out.println(cb2);
}
}
The code above generates the following result.