小衲补充一点: 以下是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()就真正起作用了
以下是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()就真正起作用了