19.字符串流(只做了解)

public class StringArrayDemo {
    
    public static void main(String[] args) throws IOException {
        
        //写
        StringWriter sw = new StringWriter();
        sw.write("滚滚长江东逝水,浪花淘尽英雄,是非成败转头空.青山依旧在,几度夕阳红 ");
        
        StringReader sr = new StringReader(sw.toString());
        char[] buffer = new char[1024];
        int len = -1;
        while ((len = sr.read(buffer)) != -1) {
            System.out.println(new String(buffer,0,len));
        }
        sw.close();
        sr.close();
    }
}

你可能感兴趣的:(19.字符串流(只做了解))