BufferedInputStream close() method in Java with Examples
The close() method of BufferedInputStream class in Java closes the input stream and releases any system resources associated with it. Once the close() method is called, reading from any input file is banned and the system will throw an IOException. To tackle the issue, the user might use a try-catch block, to catch any such exception and throw a proper instruction.
public void close()
Parameters: This method does not accept any parameters.
Return value: This method does not return any value.
Overrides: The method is overridden by close in class FilterInputStream.
Exception: This method throws IOException if any input-output error occurs.
Below programs illustrates close() method in BufferedInputStream class in IO package:
Program 1: Assume the existence of file “c:/demo.txt”.
Remaining Byte: 13
Program 2: Assume the existence of file “c:/demo.txt”.
5 Error: Sorry 'buffInputStr' is closed