Can you give us the full text of the error you are getting, and where/what in your code it is being applied to.
If this is not a compiler error or warning and is from some code checking tool then can you tell us what the tool is.
I will say that you have two
os.close() calls there, which is is unnecessary.
Also, when using the solution (try-with-resources) given in the StackOverflow
thread, what problem do you get?