java code for sample projects i/o
TRANSCRIPT
I/O Functionality Project Page 1
I/O Functionality Project
Fish.java File
// Fish.java - This program reads names of fish from an input file and // prints them to the user's screen. // Input: fish.dat. // Output: Names of fish. import java.io.*; // Import class for file input. public class Fish { public static void main(String args[]) throws Exception { // Declare variables here. String fishName; // Open input file. FileReaderfr = new FileReader("fish.dat"); // CreateBufferedReader object. BufferedReaderbr = new BufferedReader(fr);
JavaCode for Sample Projects
I/O Functionality Project Page 2
// Write while loop that tests for EOF here. while((fishName = br.readLine()) != null) // Print fish name in body of loop. { fishName = br.readLine(); System.out.println(fishName); } br.close(); System.exit(0); } // End of main() method. } // End of Fish class.