java中讲讲StringReader的用法

StringReader的用法
StringReader是Reader的继承类,从字面上就可看出,它是专门处理字符串的。
马克- to-win:马克 java社区:防盗版实名手机尾号: 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个字节, 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);
        }

    }
}


结果:

你们他们a我们





a