The following are 3 different ways to close a output writer. The first one puts close() method in try clause, the second one puts close in finally clause, and the third one uses a try-with-resources statement. Which one is the right or the best?
{PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(“out.txt”, true)));out.println(“the text”);out.close();} catch (IOException e) {e.printStackTrace();},昨晚多几分钟的准备,今天少几小时的麻烦。