Why need PrintWriter?

前端 未结 3 1553
梦谈多话
梦谈多话 2021-02-06 07:40

I am really confused about the purpose of various io classes, for example, If we have BufferedWriter, why we need a PrintWriter?

BufferedReader reader = new Buff         


        
3条回答
  •  攒了一身酷
    2021-02-06 08:07

    The main reason to use the PrintWriter is to get access to the printXXX methods (like println(int)). You can essentially use a PrintWriter to write to a file just like you would use System.out to write to the console.

    A BufferedWriter is an efficient way to write to a file (or anything else) as it will buffer the characters in Java memory before writing to the file.

提交回复
热议问题