Java StringReader Example

StringReader is extending from the Reader class. If you have string and wants to convert that to a Reader object, then StringReader is useful. It is a specialized version for using the Reader with strings. If you would like to read the Files, then choose FileReader instead of StringReader.

This class has only one constructor which takes the String object as the parameter. Lets look at the example to understand how to use the StringReader class.



 * Java StringReader Example
 * @author Krishna
public class StringReaderExample {

	 * @param args
	public static void main(String[] args) throws IOException {
		String str = "StringReader Example Program!!";

		//Create StringReader instance
		StringReader reader = new StringReader(str);
		int c =;
		while (c != -1){
			//Converting to character
		//Closing the file io




StringReader Example Program!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!