java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.Reader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.CharArrayReader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
This class implements a character buffer that can be used as a character-input stream.
Constructor | Summary |
---|---|
CharArrayReader(char[] buf) | Creates a CharArrayReader from the specified array of chars. |
CharArrayReader(char[] buf, int offset, int length) | Creates a CharArrayReader from the specified array of chars. |
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. |
int | read(char[] b, int off, int len) | Reads characters into a portion of an array. |
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 if it has never been marked. |
long | skip(long n) | Skips characters. |
import java.io.CharArrayReader;
import java.io.IOException;
public class Main {
public static void main(String args[]) throws IOException {
CharArrayReader inStream;
inStream = new CharArrayReader(new char[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' });
int ch = 0;
StringBuffer sb = new StringBuffer("");
while ((ch = inStream.read()) != -1)
sb.append((char) ch);
String s = sb.toString();
System.out.println(s.length() + " characters were read");
System.out.println("They are: " + s);
}
}
The output:
10 characters were read
They are: java2s.com
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |