I'll be having lot of files in a directory. I'll be just getting the file names using File.getName()
and log them to a log file. I presume, I don't need to close the file since I'm not doing any read/write operation in it.
Is this correct?
I'll be having lot of files in a directory. I'll be just getting the file names using File.getName()
and log them to a log file. I presume, I don't need to close the file since I'm not doing any read/write operation in it.
Is this correct?
You never have to close File
s, because it is basically a representation of a path. Only Streams and Readers/Writers. In fact, File
does not even have a close()
method.
Only resources needed to be close.
In java API there is a interface Closeable Interface, those classes implement this interface they need to be close after use.
close() //method is in that interface..
And use of close is
It closes the stream and releases any system resources associated with it.
If the stream is already closed then invoking this method has no effect.
File
is no need to be close
Yes, that's correct. When you open a file by creating a FileInputStream
or a FileOutputStream
, you must close the stream at the end.