PrintWriter vs FileWriter in Java

后端 未结 7 1123
谎友^
谎友^ 2020-11-29 19:36

Are PrintWriter and FileWriter in Java the same and no matter which one to use? So far I have used both because their results are the same. Is there some special cases where

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 20:03

    just to provide more info related to FLUSH and Close menthod related to FileOutputStream

    flush() ---just makes sure that any buffered data is written to disk flushed compltely and ready to write again to the stream (or writer) afterwards.

    close() ----flushes the data and closes any file handles, sockets or whatever.Now connection has been lost and you can't write anything to outputStream.

提交回复
热议问题