Skip to content
Related Articles
Open in App
Not now

Related Articles

ObjectInputStream available() method in Java with examples

Improve Article
Save Article
  • Last Updated : 28 May, 2019
Improve Article
Save Article

The available() method of the ObjectInputStream class in Java returns the number of bytes that can be read without blocking the stream.


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:

// Java program to illustrate
// the above method
public class GFG {
    public static void main(String[] args) throws Exception
        FileOutputStream out
            = new FileOutputStream("gopal.txt");
        ObjectOutputStream out1
            = new ObjectOutputStream(out);
        // write something in the file
        out1.writeUTF("Geeks For Geeks");
        // Flushes the Stream
        // Closes the stream
        // create an ObjectInputStream
        // for the file we created before
        ObjectInputStream example
            = new ObjectInputStream(
                new FileInputStream(
        // Print the number of bytes available



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!