Do I have to close FileOutputStream which is wrapped by PrintStream?

前端 未结 5 1743
醉话见心
醉话见心 2020-12-05 07:43

I\'m using FileOutputStream with PrintStream like this:

class PrintStreamDemo {  
    public static void main(String args[]) { 
            


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 08:33

    No , here is implementation of PrintStream's close() method:

    public void close() {
        synchronized (this) {
            if (! closing) {
            closing = true;
            try {
                textOut.close();
                out.close();
            }
            catch (IOException x) {
                trouble = true;
            }
            textOut = null;
            charOut = null;
            out = null;
            }
        }
    

    You can see out.close(); which closes output stream.

提交回复
热议问题