PrintWriter vs FileWriter in Java

后端 未结 7 1113
谎友^
谎友^ 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:08

    The java.io.PrintWriter in Java5+ allowed for a convenience method/constructor that writes to file. From the Javadoc;

    Creates a new PrintWriter, without automatic line flushing, with the specified file. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the default charset for this instance of the Java virtual machine.

    0 讨论(0)
提交回复
热议问题