Consider a BufferedReader as below:
writer = new BufferedWriter(new FileWriter(new File("File.txt"), true));
In this case at the end of the application, I am closing the writer
with writer.close()
Will this be enough? Won't that FileWriter created with new FileWriter(new File("File.txt"), true)
need to be closed?
It is not necessary to close it, because BufferedWriter takes care of closing the writer it wraps.
To convince you, this is the source code of the close method of BufferedWriter:
public void close() throws IOException {
synchronized (lock) {
if (out == null) {
return;
}
try {
flushBuffer();
} finally {
out.close();
out = null;
cb = null;
}
}
}