黑马程序员技术交流社区

标题: io的flush方法 [打印本页]

作者: 彭盼    时间: 2012-4-16 23:36
标题: io的flush方法
请问字符输出流中的flush方法真正的作用是什么,请看下面简单的一段程序:

import java.io.*;
class test
{
        public static void main(String[] args) throws IOException
        {
                System.out.println("Hello World!");
                InputStream in=System.in;
                OutputStream out=System.out;
                int s=0;
                byte[] buf=new byte[5];
        while((s=in.read(buf))>0   )
                         {
                         out.write(buf,0,s);
                         //out.flush();
             }
                out.close();
        }
}

在这里我不管要不要flush(),结果是一样的,都会将键盘输入的数据打印到控制台


作者: s476596497    时间: 2014-1-21 08:20
你要是把out.close();注释掉,就有区别了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2