StringReader class read()method example
Reads a single character.
StringReader class read()method example. This example shows you how to use read()method.This method Reads a single character.
Here is the code:-
/**
* @Program that Reads a single character.
* Read.java
* Author:-RoseIndia Team
* Date:-29-May-2008
*/
import java.io.*;
public class Read {
public static void main(String[] args) {
try
{
String s = "RoseIndia";
//creating the String Reader
StringReader sr = new StringReader(s);
System.out.println("The Array is: ");
for (int i=0;i<s.length();i++)
{
if (sr.ready())
{
//Reads a single character.
char c = (char)sr.read();
System.out.println(c);
}
else
{
break;
}
}
//Closes the stream
sr.close();
}
catch(IOException e)
{
System.out.print(e.toString());
}
}
} |
Output of the program:-
The Array is:
R
o
s
e
I
n
d
i
a |
|