Java BufferedReader close() method example

HQ » Java Tutorial » java.io » BufferedReader » Java BufferedReader close() method example
Java BufferedReader close() method example 2018-02-16T07:27:49+00:00

java.io.BufferedReader close()

Description :

This java tutorial shows how to use the close() method of BufferedReader class of java.io package. This method returns void and closes the stream thus further invocation of read(), ready(), readLine(), mark(), reset(), and skip() will result to IOException.

Method Syntax :

public void close() throws IOException

Parameter Input :

DataType Parameter Description
N/A N/A N/A

Method Returns :

This method returns void and closes the stream for further reading.

Compatibility Version :

Requires Java 1.1 and up

Exception :

None

Discussion :

The scanner close() is used to make sure that there is no memory leak happen on our program. And also most importantly to recover memory allocation allotted for this BufferedReader object. This will tell the JVM that this BufferedReader object is ready for garbage collection.

Java Code Example :

This java example source code demonstrates the use of close() method of the BufferedReader class. Basically we just read the user input from the console and then we close the reader using the close() method.

Sample Output :

Running the close() method example source code of Scanner class will give you the following output

java BufferedReader close() method example

java BufferedReader close() method example

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close