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 does not accepts any parameter.
Return Value: The function returns the total no of bytes from the Input Strem to be read.
Below is the implementation of the above function:
Program 1:
// Java program to implement // the above function import java.io.*; public class Main { public static void main(String[] args) throws Exception { // Array byte[] buffer = { 71, 69, 69, 75, 83 }; // Create InputStream ByteArrayInputStream geek = new ByteArrayInputStream(buffer); // Use the function to get the number // of available int number = geek.available(); // Print System.out.println("Use of available() method : " + number); } } |
Use of available() method : 5
Program 2:
// Java program to implement // the above function import java.io.*; public class Main { public static void main(String[] args) throws Exception { // Array byte[] buffer = { 1, 2, 3, 4 }; // Create InputStream ByteArrayInputStream geek = new ByteArrayInputStream(buffer); // Use the function to get the number // of available int number = geek.available(); // Print System.out.println("Use of available() method : " + number); } } |
Use of available() method : 4
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayInputStream.html#available()
Recommended Posts:
- ByteArrayInputStream close() method in Java with Examples
- ByteArrayInputStream skip() method in Java with Examples
- ByteArrayInputStream reset() method in Java with Examples
- ByteArrayInputStream markSupported() method in Java with Examples
- ByteArrayInputStream mark() method in Java with Examples
- Java.io.ByteArrayInputStream class in Java
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


