2.1 StringReader的用法
StringReader是Reader的继承类,从字面上就可看出,它是专门处理字符串的。
例: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个字节, 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);
}
}
}
更多请见:https://blog.youkuaiyun.com/qq_44639795/article/details/102608658
本文介绍了Java中StringReader类的基本用法,通过实例演示了如何将多行字符串转换为StringReader对象,并逐字符读取输出。适合Java初学者及需要了解StringReader特性的开发者。
597

被折叠的 条评论
为什么被折叠?



