我正在學習如何在java中讀取文件。這種差異困擾着我。我認爲這是突出的差異,我不太清楚。爲什麼新的File()不應該放入try塊中,但是新的FileReader(「input.txt」)應該放在try塊中?
File inputFile = new File("input.txt");
// is perfect fine even if input.txt doesn't exist. Why?
// but
FileReader fr = new FileReader("input.txt");
// should be put into try.. catch block?? or compiler error