際際滷

際際滷Share a Scribd company logo
JavaCode for Sample Projects
                                                    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);


I/O Functionality Project                                                       Page 1
// 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.




I/O Functionality Project                                        Page 2

More Related Content

Java Code For Sample Projects I/O

  • 1. JavaCode for Sample Projects 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); I/O Functionality Project Page 1
  • 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. I/O Functionality Project Page 2