How do I close a file after accessing it?

Creating a new instance of File doesn't
open the file - that's why File doesn't
have a close method. The only way you can
access the contents of a file is using RandomAccessFile,
FileInputStream, FileOutputStream.
FileReader, or FileWriter.
Each of these classes does have an explicit
close() method.

Note that you should always make it a practice to close
your file streams after you have finished using them.
It is not enough to set the stream reference to null
because you are likely to run out of available file descriptors
long before you run out of VM memory - and garbage collection
is only triggered by memory shortage, not shortage of
descriptors.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.