DataInputStream readDouble() in Java

readDouble(): This method is available in the java.io.DataInputStream class of Java.

Syntax:

double java.io.DataInputStream.readDouble() throws IOException

This method sees the general contract of the readDouble method of DataInput. Bytes for this operation are read from the contained input stream.

Parameters: NA

Returns: the next eight bytes of this input stream is interpreted as a double.

Throws:

1. EOFException - if this input stream reaches the end before reading eight bytes.

2. IOException - the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.

Approach

Java

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class DataInputStreamreadDouble {
    public static void main(String[] args) throws IOException {

        InputStream in = new FileInputStream("hello.txt");
        DataInputStream dataInputStream =
new DataInputStream(in);

        System.out.println(dataInputStream.readDouble());

        dataInputStream.close();
    }
}

Output:

3.8236210799062275E15


No comments:

Post a Comment