BufferedReader close() in java

close(): This method is available in the java.io.BufferedReader class of Java.

Syntax:

void java.io.BufferedReader.close() throws IOException

This method closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(),mark(), reset(), or skip() invocations will throw an IOException.

Note: Closing a previously closed stream has no effect.

Parameters: NA

Throws:

IOException - If an I/O error occurs

Returns: NA

Approach

Java

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class BufferedReaderclose {
    public static void main(String[] args) throws IOException {

        FileReader fileReader = new FileReader("D:\\hello.txt");
        BufferedReader bufferedReader =
new BufferedReader(fileReader);

        System.out.println("Closing the read buffer");
        bufferedReader.close();

    }
}

Output:

Closing the read buffer


No comments:

Post a Comment