StringReader

In this chapter you will learn:

  1. What is StringReader and how to use Java StringReader

Use StringReader

StringReader is a character stream whose source is a string.

import java.io.StringReader;
//from  j  av a  2s .  c o m
public class Main {
  public static void main(String[] args) throws Exception{
    StringReader reader = new StringReader("java2s.com");
    int ch = 0;
    while(true){
      ch =  reader.read();
      if(ch == -1){
        break;
      }
      System.out.println((char)ch);
    }
  }
}

The output:

j//  j  a  v a2 s  .c o  m
a
v
a
2
s
.
c
o
m

Next chapter...

What you will learn in the next chapter:

  1. What is LineNumberReader and how to use Java LineNumberReader