I have read that file is an unmanaged resource and won't be taken care of by garbage collector.
If you don't close a file, I am sure the reference to the file would be garbage collected if there is nothing referencing it. So what exactly stays open? Is it something at the operating system level? Like for SQL connections I know the OS keeps the TCP port open and you may eventually run out of ports. But what is it that is left open in case of a file?
The garbage collector will definitely clear the memory if there is no longer a reference to the open file. However, it will happen only when the collector runs. Until that point, that resource stays in memory.
However, it is a good idea to close it because if you have many such occurrences of files being left open, you have the risk of running out of memory if there are enough threads generated that open files but you do not close them - eventually hitting the JVM memory max size before GC kicks in.