Converting a character array to a Reader

Use the class CharArrayReader. Once you have wrapped it into a reader, you can use other readers to access the data, as shown in following example.

Main.java:

import java.io.*;
 
public class Main {
   public static void main(String args[]) {
      char array[] = { 'h', 'e', 'l', 'l', 'o', ',', 'n', 
                       'w', 'o', 'r', 'l', 'd', '!' };
      CharArrayReader car = new CharArrayReader(array);
 
      BufferedReader br = new BufferedReader(car);
      String line;
      while ((line = br.readLine()) != null) {
         System.out.println(line);
      }
   }
}

outputs:

hello,
world!