BufferedReader
improves performance by buffering input.
It has two constructors:
BufferedReader(Reader inputStream)
BufferedReader(Reader inputStream, int bufSize)
import java.io.BufferedReader; import java.io.CharArrayReader; import java.io.IOException; public class Main { public static void main(String args[]) throws IOException { String s = "This is a test from demo2s.com.\n"; char buf[] = new char[s.length()]; s.getChars(0, s.length(), buf, 0);//from w ww .j a v a 2 s. co m CharArrayReader in = new CharArrayReader(buf); try (BufferedReader f = new BufferedReader(in)) { int c = 0; while ((c = f.read()) != -1) { System.out.print((char) c); } } catch (IOException e) { System.out.println("I/O Error: " + e); } } }