This is correct.
as I know, a try can have only one finally block and is used to recover resources and close objects created to free memory.
This is not correct.
try with resources reduces code of catch and finally. we don't have to catch exceptions and recover resources using finally it is done by try with resources it self so reduces code writing and makes it simple.
instance variables should be defined with private access modifier semicolon is not needed in try with resource block if only one resource is mentioned.
Yes, you instantiated an object in line 21; where do you close it?
you may suffer an Exception from the finally. The finally should be inside a try.
Create your readers and writers for files as local variables. Don't make them fields.
The private method may be called more than once. You are now trying to write to a closed Writer. That problem would not have occurred if you had that Writer as a local variable.
Ganish Patil wrote: . . .
In private method logWrite i closed that after use
. . .
really splendid. thank you Campbell. I wish would have had teacher like you in my 6 years of education.
The private method may be called more than once.
Thank goodness for try‑with‑resources.
Stephan van Hulst wrote: . . .
Actually, for those working with older Java versions, the correct way of doing this is:
. . .