import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;public class FlushTest {
public static void main(String args[]) {
String strings[] = {"a", "b", "c", "d", "e"};
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedOutputStream buff = new BufferedOutputStream(out);
try {
for (int i = 0; i < strings.length; i++) {
buff.write(strings[i].getBytes("UTF-8"));
buff.flush(); // TODO: COMMENT THIS
System.out.println("the " + i + "th time to write it is: " +
new String(out.toByteArray()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}flush() 只用在 BufferedStream 上面
其实你可以参考TIJ中的第15章 网络编程中的例子。