The readBoolean() method of DataInputStream class in Java is used to read one input byte and if the byte read is zero this method returns false and if the byte read is nonzero then this method returns true.
public final boolean readBoolean() throws IOException
Specified By: This method is specified by readBoolean() method of DataInput interface.
Parameters: This method does not accept any parameter.
Return value: This method returns the boolean value read i.e true or false.
- EOFException – It throws EOFException if the input stream is ended.
- IOException – This method throws IOException if the stream is closed or some other I/O error occurs.
Below programs illustrate readBoolean() method in DataInputStream class in IO package:
true false false true false
true true true true false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.