In InputStreams, read() calls are said to be "blocking" method calls. That means that if no data is available at the time of the method call, the method will wait for data to be made available.

The available() method tells you how many bytes can be read until the read() call will block the execution flow of your program. On most of the input streams, all call to read() are blocking, that's why available returns 0 by default.

However, on some streams (such as BufferedInputStream, that have an internal buffer), some bytes are read and kept in memory, so you can read them without blocking the program flow. In this case, the available() method tells you how many bytes are kept in the buffer.

Answer from Vivien Barousse on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › InputStream.html
InputStream (Java Platform SE 7 )
It is never correct to use the ... an IOException if this input stream has been closed by invoking the close() method. The available method for class InputStream always returns 0....
🌐
Tutorialspoint
tutorialspoint.com › java › io › fileinputstream_available.htm
Java - FileInputStream available() method
The Java FileInputStream available() method returns the number of bytes that can be read from the file input stream without blocking. It does not return the total file size but rather the number of remaining unread bytes in the stream.
🌐
IncludeHelp
includehelp.com › java › inputstream-available-method-with-example.aspx
Java InputStream available() Method with Example
// Java program to demonstrate the example // of int available() method of InputStream import java.io.*; public class AvailableOfIS { public static void main(String[] args) throws Exception { InputStream is_stm = null; int val = 0; try { // Instantiates FileInputStream is_stm = new FileInputStream("D:\\includehelp.txt"); // Loop to read until available // bytes left while ((val = is_stm.read()) != -1) { // By using available() method is to // return the available bytes to be read int avail_bytes = is_stm.available(); // Display corresponding byte value byte b = (byte) val; // Display value of
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › io › InputStream.html
InputStream (Java SE 21 & JDK 21)
January 20, 2026 - It is never correct to use the ... close() method. ... This method should be overridden by subclasses. ... The available method of InputStream always returns 0....
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › io › InputStream.html
InputStream (Java SE 11 & JDK 11 )
January 20, 2026 - It is never correct to use the ... if this input stream has been closed by invoking the close() method. The available method of InputStream always returns 0....
🌐
GitHub
github.com › AdoptOpenJDK › openjdk-jdk11 › blob › master › src › java.base › share › classes › java › io › InputStream.java
openjdk-jdk11/src/java.base/share/classes/java/io/InputStream.java at master · AdoptOpenJDK/openjdk-jdk11
return new InputStream() { private volatile boolean closed; · private void ensureOpen() throws IOException { if (closed) { throw new IOException("Stream closed"); } } · @Override · public int available () throws IOException { ensureOpen(); return 0; } ·
Author   AdoptOpenJDK
🌐
Tabnine
tabnine.com › home page › code › java › java.io.inputstream
Java Examples & Tutorials of InputStream.available (java.io) | Tabnine
Payload payload = blob.getPayload(); InputStream is = payload.getInput(); File tempFile = new File(downloadDir, name + ".tmp"); Timer.Context downloadContext = downloadTimer.time(); try { byte[] buf = new byte[BUF_SIZE]; while (read < length) { int avail = Math.min(is.available(), BUF_SIZE); if (avail < 0) { try { Thread.sleep(100); } catch (Exception ex) {} } else { int readLength = is.read(buf); read += readLength; out.write(buf, 0, readLength); File permFile = new File(downloadDir, name); if (tempFile.renameTo(permFile)) { notifyListeners(permFile); } else { throw new IOException("Could not rename file"); origin: alibaba/canal ·
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java-io › inputstream.html
Java InputStream
The Java InputStream class contains a method called readAllBytes() (since Java 9). This method reads all the bytes available in the InputStream and returns a single byte array with the bytes in. This method is useful if you need to read all bytes from a file via a FileInputStream into a byte array.
🌐
Android Developers
developer.android.com › api reference › inputstream
InputStream | API reference | Android Developers
February 13, 2026 - Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Usc
physics.usc.edu › java › api › java.io.InputStream.html
Class java.io.InputStream
InputStream() available() Returns the number of bytes that can be read without blocking. close() Closes the input stream. mark(int) Marks the current position in the input stream. markSupported() Returns a boolean indicating whether or not this stream type supports mark/reset.
🌐
GeeksforGeeks
geeksforgeeks.org › java › bytearrayinputstream-available-method-in-java-with-examples
ByteArrayInputStream available() method in Java with Examples - GeeksforGeeks
July 11, 2025 - 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.
🌐
Coderanch
coderanch.com › t › 612110 › java › method-returning
available() method returning zero (Sockets and Internet Protocols forum at Coderanch)
Hi I am the first time on the forum and I am having a problem with retrieving the data from the InputStream. I have a Client program that sends the data to the ISeries Server and get a response and display it on a Web page. The problem is that when I run the program interactively, the available method returns zero, but when run in a debug mode, the available() returns the expected number of bytes.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › io › InputStream.html
InputStream (Java SE 17 & JDK 17)
January 20, 2026 - It is never correct to use the ... if this input stream has been closed by invoking the close() method. The available method of InputStream always returns 0....
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-7134707
[JDK-7134707] InputStream.available() doesn't reliably return ...
This breaks tests and might cause unexpected issues when available() is being used. REGRESSION. Last worked in version 7 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Run the test case of the github project shown above. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - available() should return 19 after the first byte of the second payload "a" has been read.
🌐
Programiz
programiz.com › java-programming › inputstream
Java InputStream (With Example)
In order to create an InputStream, we must import the java.io.InputStream package first.
🌐
GeeksforGeeks
geeksforgeeks.org › java › fileinputstream-available-method-in-java-with-examples
FileInputStream available() Method in Java with Examples - GeeksforGeeks
December 29, 2021 - The available() method of FileInputStream class is used to return the estimated number of remaining bytes that can be read from the input stream without blocking. This method returns the number of bytes remaining to read from the file.
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › io › InputStream.html
InputStream (Java SE 10 & JDK 10 )
It is never correct to use the ... an IOException if this input stream has been closed by invoking the close() method. The available method for class InputStream always returns 0....
🌐
Studytonight
studytonight.com › java-file-io › java-fileinputstream-available-method
Java FileInputStream available() Method - Studytonight
Java FileInputStream available() method: This method is used to return the number of remaining bytes to be read from the current input stream, without blocking