Lab 22: Reading Files


Due Wednesday, November 29 at 11:59 PM

Goals for This Lab

By the time you have completed this work, you should be able to:

Provided files:

Step-by-Step Instructions

Step 1: Download Example Files

Download the following two files:

  1. colors.txt
  2. elements.txt

These will be used as example input files for the rest of this lab.

Step 2: Edit PrintEveryOtherLine.java

This program will open a given file for reading, specified on the command-line. It will then print out every other line of the file, printing the first line of the file. For example, if you run your program with the command-line arguments colors.txt, you should get the following output:

1: Red
3: Green
5: Orange
7: Black
9: Pink

The comments in the program provide more details.

Step 3: Edit ConcatenateOutput.java

This program will open a series of files for reading, and print out their contents in the same order as provided. For example, if you run your program with the command-line arguments colors.txt elements.txt, you should get the following output:

1: Red
2: Blue
3: Green
4: Yellow
5: Orange
6: Purple
7: Black
8: White
9: Pink
1: Hydrogen
2: Helium
3: Lithium
4: Beryllium
5: Boron
6: Carbon
7: Nitrogen
8: Oxygen
9: Fluorine

The comments in the program provide more details.

Step 4: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 22”. From here, you can upload your code. Specifically, you must turn in the following two files:

In addition, if you collaborated with anyone else, be sure to download collaborators.txt and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.