The BufferedInputStream class adds new attributes to other input streams, an ability to buffer the input. When BufferedInputStream is created, an internal buffer array is created.
The available() method of BufferedInputStream class is used to know the number of bytes available to read from the internal buffer array, until a situation arises where there is no data available to read. The invocation of the method read() will block the execution flow of the program and wait for the data to be made available.
public int available()
Parameters: This method does not take any parameters.
Return value: The method is used to return the sum of bytes remained to be read from this input stream without any blockage.
Exception: The method throws IOException if an error related to input-output occurs or when the close method has been used to close the input stream.
Example 1: Below program illustrates the use of available() method, assuming the existence of file “d:/demo.txt”.
Example 2: Below program illustrates the use of available() method, assuming the existence of file “d:/demo.txt”.
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.