Thursday, April 22, 2010

การใช้งาน StringStream

// StringStream.java

import java.io.*;

class StringStream {

    public static void main(String args[]) throws IOException {

        String s = "Hello! how do you do?";

        StringReader sr = new StringReader(s);

        StringWriter sw = new StringWriter();

        int c;

        while ((c = sr.read()) != -1)

            sw.write(c);

        sr.close();

        sw.close();

        System.out.println(sw.toString());

    }

}

No comments:

Post a Comment