Difference between PrintWriter and FileWriter class

后端 未结 4 1631
灰色年华
灰色年华 2021-02-05 21:17
try{

    File file = new File(\"write.txt\");
    FileWriter writer = new FileWriter(file);

    PrintWriter printWriter = new PrintWriter(writer);
    printWriter.prin         


        
4条回答
  •  清酒与你
    2021-02-05 21:58

    While FileWriter has only a basic set of methods, PrintWriter has a rich set of convinience methods, one of them is in your example - PrintWriter.println.

    You should also keep in mind that "methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError()"

提交回复
热议问题