希望大家多多指正
CharArrayReader,StringReader
主要用于字符数组和字符串的读取
public class CharArrayReader_StringReader {
public static void main(String[] args) {
String s = "Hello World";
CharArrayReader car = new CharArrayReader(s.toCharArray());
StringReader sr = new StringReader(s);
try {
int c;
while ((c = car.read()) >= 0) {
System.out.print((char)c + "\t");
}
System.out.println();
while ((c = sr.read()) >= 0) {
System.out.print((char)c + "\t");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
控制台结果:
H e l l o W o r l d
H e l l o W o r l d