Converting a String to a Reader

Java provides a StringReader class expressly for this purpose. java.io.StringReader has a constructor that takes a String argument.

import java.io.StringReader;
...
String myString = 'Testing 1 2 3...';
StringReader myStringReader = new StringReader(myString);
 
// Then, use standard Reader-reading techniques
// to access the Reader
int len = -1; // Number of chars read
char [] buf = new char[256]; // Characters read from Reader
try { 
   while ((len = myStringReader.read(buf, 0, 256)) != -1) {
      System.out.println('Next chunk from Reader is ' + (new String(buf, 0, len)));
   }
} catch (IOException ioe) {
   System.err.println("Error reading from Reader :" + e.getMessage());
}