StringReader类是秒的子类阅读器类,它可用于读出的字符流中充当源StringReader一个字符串的形式。该StringReader类将覆盖所有从阅读器类的方法。StringReader类的重要方法跳过(), , close(),,mark()markSupported()reset()等。
语法Public class StringReader extends Reader
示例import java.io.StringReader;
import java.io.IOException;
public class StringReaderTest {
public static void main(String[] args) {
String str = "Welcome to nhooo.com";
StringReader strReader = new StringReader(str);
try {
int i;
while((i=strReader.read()) != -1) {
System.out.print((char)i);
}
} catch(IOException ioe) {
System.out.println(ioe);
} finally {
if(strReader != null) {
try {
strReader.close();
} catch(Exception e) {
System.out.println(e);
}
}
}
}
}
输出结果Welcome to nhooo.com