ObjectInputStream readBoolean() method in Java with examples Last Updated : 28 May, 2019 Comments Improve Suggest changes Like Article Like Report The readBoolean() method of the ObjectInputStream class in Java reads a boolean from the stream. Syntax: public boolean readBoolean() Parameters: This method does not accept any parameter. Return Value: This method returns the boolean that has been read. Errors and Exceptions: The function throws two exceptions which is described below: EOFException: The function is thrown if the end of file is reached. IOException: The function is thrown if an I/O error has occurred. Below program illustrate the above method: Program 1: Java // Java program to illustrate // the above method import java.io.*; public class GFG { public static void main(String[] args) { try { // create a new file // with an ObjectOutputStream FileOutputStream out = new FileOutputStream("gopal.txt"); ObjectOutputStream out1 = new ObjectOutputStream(out); // write out1.writeUTF("Geeks for Geeks"); // Flushes the stream out1.flush(); // create an ObjectInputStream // for the file ObjectInputStream example = new ObjectInputStream( new FileInputStream("gopal.txt")); // Read from the stream for (int i = 0; i < example.available();) { System.out.print("" + (char)example.read()); } } catch (Exception ex) { ex.printStackTrace(); } } } Output: Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ObjectInputStream.html#readBoolean() Comment More infoAdvertise with us Next Article ObjectInputStream readBoolean() method in Java with examples gopaldave Follow Improve Article Tags : Java Java-Functions Java-IO package Java-ObjectInputStream Practice Tags : Java Similar Reads ObjectInputStream read() method in Java with examples The read() method of the ObjectInputStream class in Java reads a byte of data. This method wont run if there is no data. Syntax: public int read() Parameters: This method does not accept any parameter. Return Value: This method returns the byte read, or -1 if the end of the stream is reached. Except 1 min read ObjectInputStream readByte() method in Java with examples The readByte() method of the ObjectInputStream class in Java is used to read the 8 bit (byte). Syntax: public byte readByte() Parameters: This method does not accept any parameter. Return Value: This method returns the 8 bit byte read Errors and Exceptions: The function throws three exceptions which 2 min read PushbackInputStream read() method in Java with Examples The read() method of PushbackInputStream class in Java is of two types: The read() method of PushbackInputStream class in Java is used to read the next byte of data from the input stream. This method returns the read byte from the input stream in the form of an integer. Syntax: public int read() thr 4 min read ObjectInputStream close() method in Java with examples The close() method of the ObjectInputStream class in Java closes the input stream. Syntax: public void close() Parameters: This method does not accept any parameter. Return Value: This method does not returns anything. Below program illustrate the above method: Program 1: Java // Java program to ill 1 min read PushbackInputStream unread() method in Java with Examples The unread() method of PushbackInputStream class in Java is of three types: The unread(int b) method of PushbackInputStream class in Java is used to push back a byte by copying it to the front of the pushback buffer. After revoking this method, when the next byte is read it has the value equal to th 6 min read ObjectInputStream available() method in Java with examples 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 1 min read Reader read() method in Java with Examples The read() method of Reader Class in Java is used to read a single character from the stream. This method blocks the stream till: It has taken some input from the stream. Some IOException has occurred It has reached the end of the stream while reading. This method is declared as abstract method. It 3 min read PushbackInputStream skip() method in Java with Examples The skip(long n) method of PushbackInputStream class in Java is used to skip over and discards n bytes of data from this input stream. This method first skips over the bytes in the pushback buffer, and then calls the skip method of the main input stream. It returns the actual number of bytes skipped 2 min read PushbackInputStream mark() method in Java with Examples The mark() method of PushbackInputStream class in Java is used to mark the current position in the input stream. This method does nothing for PushbackInputStream. Syntax: public void mark(int readlimit) Overrides: This method overrides the mark() method of FilterInputStream class. Parameters: This m 2 min read ObjectInputStream defaultReadObject() method in Java with examples The defaultReadObject() method of the ObjectInputStream class in Java is used to read the non-static and non-transient fields of the current class from this stream. Syntax: public void defaultReadObject() Parameters: This method does not accept any parameter. Return Value: This method returns the va 2 min read Like