ByteArrayInputStream available() method in Java with Examples
Last Updated :
13 Sep, 2021
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 accept any parameter.
Return Value: The function returns the total no of bytes from the Input Stream to be read.
Below is the implementation of the above function:
Program 1:
Java
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte [] buffer = { 71 , 69 , 69 , 75 , 83 };
ByteArrayInputStream geek
= new ByteArrayInputStream(buffer);
int number = geek.available();
System.out.println( "Use of available() method : "
+ number);
}
}
|
Output:
Use of available() method : 5
Program 2:
Java
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte [] buffer = { 1 , 2 , 3 , 4 };
ByteArrayInputStream geek
= new ByteArrayInputStream(buffer);
int number = geek.available();
System.out.println( "Use of available() method : "
+ number);
}
}
|
Output:
Use of available() method : 4
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayInputStream.html#available()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...