Read double from file using DataInputStream - Java File Path IO

Java examples for File Path IO:DataInputStream

Description

Read double from file using DataInputStream

Demo Code


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
public class Main {
 
  public static void main(String[] args) {
 
    String strFilePath = "C://Folder//readDouble.txt";
   /*w w w .j  a v  a  2 s .  c om*/
    try{
      FileInputStream fin = new FileInputStream(strFilePath);
     
      DataInputStream din = new DataInputStream(fin);
     
      double d = din.readDouble();
       
      System.out.println("Double : " + d);
       
      din.close();
       
    }
    catch(FileNotFoundException fe)
    {
      System.out.println("FileNotFoundException : " + fe);
    }
    catch(IOException ioe)
    {
      System.out.println("IOException : " + ioe);
    }
  }
}

Result


Related Tutorials