把数据缓存区里的数据,立即刷新到流里。
你编过unix程序就知道了。
高级IO流是缓冲流,数据并不是马上到流里,只有缓存区满了(不是绝对的),在统一刷新到流里,flush就是用来把数据缓存区里的数据强迫刷新到流里。

解决方案 »

  1.   

    清空缓冲区,防止数据丢失,同意lusxiao(lusxiao)的说话
      

  2.   

    小衲补充一点:
    以下是java.io.OutputStream(一个抽象类)中对flush()的说明:    /**
         * Flushes this output stream and forces any buffered output bytes 
         * to be written out. The general contract of <code>flush</code> is 
         * that calling it is an indication that, if any bytes previously 
         * written have been buffered by the implementation of the output 
         * stream, such bytes should immediately be written to their 
         * intended destination.
         * <p>
         * The <code>flush</code> method of <code>OutputStream</code> does nothing.
         *
         * @exception  IOException  if an I/O error occurs.
         */另外,flush()能否真正工作,取决于子类是否真正override了这个flush()方法,
    抽象类java.io.OutputStream中的flush()不是抽象方法,但没有进行任何实现(空的
    方法体);另外,比如java.io.FileOutputStream好象也没有override这个flush()
    方法如果某个子类真正override了这个flush()方法,则这时你依然可以通过java.io.OutputStream
    来使用这个子类(多态),即用户不需要知道这个子类真正的type,但这时子类中的flush()
    将被调用,这时flush()就真正起作用了