Use DataInputStream to create double : DataInputStream « File « Java Tutorial


public class Main {
  public static void main(String[] argv) throws Exception {
    FileInputStream fileIn = new FileInputStream("data.txt");
    DataInputStream dataIn = new DataInputStream(fileIn);
    int counter = dataIn.readInt();
    double sum = 0.0;
    for (int i = 0; i < counter; i++) {
      double current = dataIn.readDouble();
      System.out.println("Just read " + current);
      sum += current;
    System.out.println("\nAverage = " + sum / counter);

11.17.1.Create DataInputStream from FileInputStream
11.17.2.Create DataInputStream from BufferedInputStream and FileInputStream
11.17.3.Create DataInputStream from ByteArrayInputStream
11.17.4.Read int from DataInputStream
11.17.5.Read double from DataInputStream
11.17.6.Read double and UTF from DataInputStream with BufferedInputStream backended
11.17.7.Read boolean from file using DataInputStream
11.17.8.Read byte array from file using DataInputStream
11.17.9.Read byte from file using DataInputStream
11.17.10.Read char from file using DataInputStream
11.17.11.Read float from file using DataInputStream
11.17.12.Read long from file using DataInputStream
11.17.13.Read short from file using DataInputStream
11.17.14.Read unsigned byte from file using DataInputStream
11.17.15.Check the class version
11.17.16.Create a compressed data file by using a DeflaterOutputStream and then read that data through an InflaterInputStream.
11.17.17.Use DataInputStream to create double
11.17.18.Testing for end of file while reading a byte at a time.
11.17.19.This class is an part implementation of DataInput. It wraps a Reader object.