Java FileReader Class close() Method with Examples
The close() method of FileReader class in Java is used to close the file reader. We can’t utilize the reader to read data after the close() method is executed. This procedure closes the stream and frees all associated system resources. Calling read(), ready(), mark(), reset(), or skip() after this method has been used will result in an IOException.
public abstract void close()
There are no parameters or values returned by this procedure.
Example 1: We verify whether the stream implements the mark() function, and after the stream’s activities are complete, we use the close() method to free up all the resources tied to or temporarily allocated for the stream; beyond this point, we can no longer utilize it.
input.txt has the following text
Example 2: When we try to utilize it, an exception like this is thrown because all of the resources necessary for the current stream have been de-allocated.
Output: Any other operation on the stream is invalidated when this method is called.