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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.