ObjectInputStream available() method in Java with examples
Last Updated :
28 May, 2019
The available() method of the ObjectInputStream class in Java returns the number of bytes that can be read without blocking the stream.
Syntax:
public int available()
Parameters: This method does not accept any parameter.
Return Value: This method returns the number of available bytes.
Below program illustrate the above method:
Program 1:
import java.io.*;
public class GFG {
public static void main(String[] args) throws Exception
{
FileOutputStream out
= new FileOutputStream( "gopal.txt" );
ObjectOutputStream out1
= new ObjectOutputStream(out);
out1.writeUTF( "Geeks For Geeks" );
out1.flush();
out1.close();
ObjectInputStream example
= new ObjectInputStream(
new FileInputStream(
"gopal.txt" ));
System.out.println(example.available());
example.close();
}
}
|
Output:
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ObjectInputStream.html#available()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...