java中講講StringReader的用法
StringReader的用法
StringReader是Reader的繼承類,從字面上就可看出,它是專門處理字符串的。
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號: 73203。
例:2.1.1
import java.io.*;
public class TestMark_to_win {
public static void main(String args[]) throws Exception {
// /////from multiline string to StringReader, then to console
String s, s1 = new String();
s = "你們" + "他們a我們" + "\n";
System.out.println(s);
/* A character stream whose source is a string. */
StringReader in2 = new StringReader(s);
int c;
/*in2.read() Read a single character,(qixy: two bytes 或1個(gè)字節(jié), so can handle chinese). or -1 if the end of the stream has been reached. Returns: The character read */
while ((c = in2.read()) != -1) {
System.out.println((char) c);
}
}
}
結(jié)果:
你們他們a我們
你
們
他
們
a
我
們