
StringReader类是Reader类的子类,它可用于读取字符流 以字符串的形式作为 StringReader 的源。 StringReader类会覆盖 Reader 类中的所有方法。 StringReader类的重要方法有skip()、close()、mark()、markSupported()、reset()等。
语法
<strong>Public class StringReader extends Reader</strong>
示例
import java.io.StringReader;
import java.io.IOException;
public class StringReaderTest {
public static void main(String[] args) {
String str = "Welcome to Tutorials Point";
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 Tutorials Point











