Java BufferedInputStream available() method with Example Last Updated : 03 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: 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". Java // Java code to illustrate available() method import java.io.*; class Testing { public static void main(String[] args) throws IOException { // create input stream 'demo.txt' // for reading containing text "GEEKS" FileInputStream inputStream = new FileInputStream("d:/demo.txt"); // convert inputStream to // bufferedInputStream BufferedInputStream buffInputStr = new BufferedInputStream(inputStream); // get the number of bytes available // to read using available() method Integer remBytes = buffInputStr.available(); // Print result System.out.println( "Remaining bytes =" + remBytes); } } Output: 5 Example 2: Below program illustrates the use of available() method, assuming the existence of file "d:/demo.txt". Java // Java code to illustrate available() method import java.io.*; class Testing { public static void main(String[] args) throws IOException { // create input stream demo.txt // for reading containing text // "GEEKSFORGEEKS" FileInputStream inputStream = new FileInputStream("d:/demo.txt"); // convert inputStream to // BufferedInputStream BufferedInputStream buffInputStr = new BufferedInputStream(inputStream); // get the number of bytes available to // read using available() method Integer remBytes = buffInputStr.available(); // Print result System.out.println( "Remaining bytes =" + remBytes); } } Output: 13 Comment More infoAdvertise with us Next Article BufferedInputStream close() method in Java with Examples T thatguyaneeket Follow Improve Article Tags : Java Java-Functions Java-IO package Java-BufferedInputStream Practice Tags : Java Similar Reads ByteArrayInputStream available() method in Java with Examples The available() method is a built-in method of the Java.io.ByteArrayInputStream returns the number of remaining bytes that can be read (or skipped over) from this input stream. It tells the total no. of bytes from the Input Stream to be read. Syntax: public int available() Parameters: The function d 2 min read BufferedInputStream read() method in Java with Examples read() method of BufferedInputStream class in Java is used to read the next byte of data from the input stream. When this read() method is called on the input stream then this read() method reads one character of the input stream at a time. Syntax: public int read() Overrides: It overrides read() me 3 min read 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 2 min read BufferedInputStream reset() method in Java with Examples The reset() method of BufferedInputStream class in Java is used to reset the position of the stream to the position at the time the mark method was last called. It is used with the combination of mark() method of the same class. General Contract: There are two cases: If mark() and reset() are suppor 3 min read BufferedInputStream skip(long) method in Java with Examples The skip(long) method of BufferedInputStream class in Java is used to skip n bytes of data from the buffered input stream. The number of bytes skipped is stored and returned as long type. The termination condition involves either of the two: Either reading into a byte array until n-bytes are covered 2 min read BufferedOutputStream write() method in Java with Examples The write(int) method of BufferedOutputStream class in Java is used to write the specified byte to the buffered output stream. The specified byte is passed as an integer to the write() method here. It is used to write one byte as a time to the BufferedOutputStream. Syntax: public void write(int b) t 3 min read Like