I wrote a method to close write to a file.
However, a senior developer suggested me to close the file inside the finally block.
This is the method I have:
private static void writetoFiles(String error) {
try {
File file = new File("errorcode.txt");
if (!file.exists()) {
file.createNewFile();
} else {
FileWriter updateerrorcode = new FileWriter("errorcode.txt");
updateerrorcode.write(error);
updateerrorcode.close();
}
} catch (IOException e) {
}
}
I read many answers in stackoverflow but all of them seemed a bit too complicated for a simple case like mine.
Any suggestions how should I go about this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…