This Java code file reads in fish names from an external text file called "fish.dat" and prints each name to the user's screen. It uses FileReader and BufferedReader objects to open the input file, reads each line of the file using a while loop until the end of file is reached, and prints out the fish name read on each line. The input and output of the program is fish names from and to standard I/O streams.
1 of 2
Downloaded 12 times
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