DataInputStream readDouble() method in Java with Examples
The readDouble() method of DataInputStream class in Java is used to read eight input bytes and returns a double value. This method reads the next eight bytes from the input stream and interprets it into double type and returns.
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public final double readDouble() throws IOException
Specified By: This method is specified by readDouble() method of DataInput interface.
Parameters: This method does not accept any parameter.
Return value: This method returns the double value interpreted by the next eight bytes of the input stream.
- EOFException – It throws EOFException if the input stream is ended before eight bytes can be read.
- IOException – This method throws IOException if the stream is closed or some other I/O error occurs.
Below programs illustrate readDouble() method in DataInputStream class in IO package:
Program 1: Assume the existence of file “demo.txt”.
Program 2: Assume the existence of file “demo.txt”.