001package edu.pdx.cs410J.core; 002 003import java.io.*; 004 005/** 006 * This program takes a file whose name is given on the command line 007 * and reads <code>double</code>s from it. It demonstrates the 008 * <code>FileInputStream</code> and <code>DataInputStream</code> 009 * classes. 010 */ 011public class ReadDoubles { 012 static PrintStream out = System.out; 013 static PrintStream err = System.err; 014 015 /** 016 * The one command line argument is the name of the file to read. 017 */ 018 public static void main(String args[]) { 019 FileInputStream fis = null; 020 try { 021 fis = new FileInputStream(args[0]); 022 023 } catch (FileNotFoundException ex) { 024 err.println("** No such file: " + args[0]); 025 } 026 027 DataInputStream dis = new DataInputStream(fis); 028 while (true) { 029 try { 030 double d = dis.readDouble(); 031 out.print(d + " "); 032 out.flush(); 033 034 } catch (EOFException ex) { 035 // All done reading 036 break; 037 038 } catch (IOException ex) { 039 err.println("** " + ex); 040 System.exit(1); 041 } 042 } 043 out.println(""); 044 } 045}