我看到别人有段代码:
public class TestPrintStream {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Use StringBuilder is just OK, I think.
OutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("Test PrintStream.");
ps.flush();
System.out.println(os.toString());
}
}
以上代码明明可以直接用StringBuilder搞定,非要弄PrintStream和OutputStream干嘛?有什么好处吗?
看来你还没有搞懂什么是StringBuilder是做什么的。。。。。
TestPrintStream
程序的目的就是为了测试/演示怎么用PrintStream吧。
好比你去商店买个手电,总要试试,虽然是白天。