Java IO Tutorial - Java PushbackReader.read(char[] cbuf, int off, int len)








Syntax

PushbackReader.read(char[] cbuf, int off, int len) has the following syntax.

public int read(char[] cbuf, int off, int len)  throws IOException

Example

In the following code shows how to use PushbackReader.read(char[] cbuf, int off, int len) method.

/*w  ww  . j av  a2s  . c o m*/
import java.io.*;

public class Main {

   public static void main(String[] args) {

      String s = "from java2s.com";

      StringReader sr = new StringReader(s);

      PushbackReader pr = new PushbackReader(sr, 20);

      char cbuf[] = new char[5];

      try {
         System.out.println(pr.read(cbuf));

         System.out.println(cbuf);

         pr.close();

      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

The code above generates the following result.