Reader.read(CharBuffer target) has the following syntax.
public int read(CharBuffer target) throws IOException
In the following code shows how to use Reader.read(CharBuffer target) method.
//ww w .j a v a2s . co m import java.io.*; import java.nio.CharBuffer; public class Main { public static void main(String[] args) { String s = "tutorial from java2s.com"; CharBuffer cb = CharBuffer.allocate(100); Reader reader = new StringReader(s); try { reader.read(cb); cb.flip(); // print the char buffer System.out.println(cb.toString()); reader.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
The code above generates the following result.