Description

Command Line Arguments

Command line arguments are arguments that can be given to a program when it is run (on the command line or in Eclipse's Run Dialogue).

The command line arguments are entered on the command line as a space-separated list. In the image below, the file filename.txt is a command line argument.

The main method takes in one argument: a String array named args[]. This array will contain any command line arguments that are passed in when we run the program. In this example, args[0] will contain "filename.txt". Note that in Java, unlike C, the command itself is not stored in args[].

In Eclipse, command line arguments can be passed to the program using the Run Dialogue. Go to Run -> Open Run Dialogue... Click on the "Arguments" tab, and your command line arguments can be entered in the "Program Arguments" box.

File I/O

In this lab we will be using a Scanner object to read from a text file. We will read information about students from the file students.txt. This text file will contain the name of the student and their ID number in the format:

name id

The first line of the file contains the number of student records in the file. This will enable us to decide on the size of data structure to use to store the students' information.

We will perform the following file operations: