Java FileReader Class close() Method with Examples Last Updated : 16 Feb, 2022 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. Java // Java Program to demonstrate the working of close() // method of FileReader class in Java import java.io.FileReader; public class GFG { public static void main(String args[]) { try { FileReader fileReader = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt"); int i; while ((i = fileReader.read()) != -1) System.out.print((char)i); fileReader.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } input.txt has the following text Output: 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. Java // Java Program to demonstrate the working of close() // method of FileReader class in Java import java.io.FileReader; public class GFG { public static void main(String args[]) { try { FileReader fileReader = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt"); int i; fileReader.close(); while ((i = fileReader.read()) != -1) System.out.print((char)i); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } Output: Any other operation on the stream is invalidated when this method is called. Comment More infoAdvertise with us Next Article Java FileReader Class close() Method with Examples D dikshanandre2403 Follow Improve Article Tags : Java Java-Functions java-file-handling Practice Tags : Java Similar Reads Java FileReader Class ready() Method with Examples Java FileReader class is used to read data from the data file. It returns the data in byte format as FileInputStream class. This is a character-oriented class that is used for file handling in Java. ready() Method of FileReader Class It checks if the file reader is ready to be read. It will return a 3 min read Java FileReader Class read() Method with Examples The read() method of FileReader class in Java is used to read and return a single character in the form of an integer value that contains the character's char value. The character read as an integer in the range of 0 to 65535 is returned by this function. If it returns -1 as an int number, it means 2 min read FileInputStream close() Method in Java with Examples FileInputStream class is helpful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. FileInputStream.close() method After any operation to the file, w 2 min read Formatter close() method in Java with Examples The close() method is a built-in method of the java.util.Formatter which closes the formatter. In case it is already closed, it will have no effect. Closing it means that it will release the resources that it is already holding. Syntax: public void close() Parameters: The function accepts no paramet 2 min read File canRead() method in Java with Examples The canRead()function is a part of the File class in Java. This function determines whether the program can read the file denoted by the abstract pathname. The function returns true if the abstract file path exists and the application is allowed to read the file.Function signature: public boolean ca 2 min read FileInputStream available() Method in Java with Examples The available() method of FileInputStream class is used to return the estimated number of remaining bytes that can be read from the input stream without blocking. This method returns the number of bytes remaining to read from the file. When a file is completely read, this function returns zero. Synt 3 min read Reader close() method in Java with Examples The close() method of Reader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effect. If an 2 min read Writer close() method in Java with Examples The close() method of Writer Class in Java is used to close the writer. Closing a writer deallocates any value in it or any resources associated with it. The Writer instance once closed won't work. Also a Writer instance once closed cannot be closed again. Syntax: public void close() Parameters: Thi 2 min read CharArrayReader close() method in Java with Examples The close() method of CharArrayReader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effe 3 min read Scanner close() method in Java with Examples The close() method ofjava.util.Scanner class closes the scanner which has been opened. If the scanner is already closed then on calling this method, it will have no effect. Syntax: public void close() Return Value: The function does not return any value. Below programs illustrate the above function: 1 min read Like