java code for sample projects i/o

2
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

Upload: jwjablonski

Post on 04-Jul-2015

413 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Java Code For Sample Projects I/O

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

Page 2: Java Code For Sample Projects I/O

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.