| java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | - | - | java.io.Reader | ||||||||||||||||||||||||||||||||||||||||||||||||
| | | |||||||||||||||||||||||||||||||||||||||||||||||||||
| | | - | - | java.io.StringReader | ||||||||||||||||||||||||||||||||||||||||||||||||
A character stream whose source is a string.
| Constructor | Summary |
|---|---|
| StringReader(String s) | Creates a new string reader. |
| Return | Method | Summary |
|---|---|---|
| void | close() | Closes the stream and releases any system resources associated with it. |
| void | mark(int readAheadLimit) | Marks the present position in the stream. |
| boolean | markSupported() | Tells whether this stream supports the mark() operation, which it does. |
| int | read() | Reads a single character. The character read, or -1 if the end of the stream has been reached. |
| int | read(char[] cbuf, int off, int len) | Reads characters into a portion of an array. The character read, or -1 if the end of the stream has been reached. |
| boolean | ready() | Tells whether this stream is ready to be read. |
| void | reset() | Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked. |
| long | skip(long ns) | Skips the specified number of characters in the stream. |
import java.io.StringReader;
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
a
v
a
2
s
.
c
o
mjava2s.com | | Contact Us | Privacy Policy |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |