Programming Assignment 1
File I/O, Console I/O, and Command-Line Arguments
Requirements
You will implement a Java console application that opens and reads the contents of text files specified as command-line arguments. For each file, the application writes to standard output the name of the file enclosed by square brackets. After writing the file name, the application writes the contents of the file with each line prefixed by its corresponding line number, a full colon, and a space.
For example, if a file with the name sample-input.txt contains these four lines:
...then the application writes the following output if the user specifies sample-input.txt on the command line:
The application processes command line arguments in the order specified by the user. If the user enters no command line arguments, the application writes no output for the first part of this assignment. If the user specifies two or more files, the application writes a blank line between the output corresponding to each file.
The application then reads lines of standard input. For each line of input, if the user enters exit
, the application terminates; otherwise, the application interprets the line as a path to a text file. The application creates or recreates this file and writes to it two lines of output, the name of the file and the current date and time. The application then closes the file, reopens it for reading, and writes its contents to standard output in the same manner as the files in the first part of this assignment.
The application writes the following prompt before attempting to read each line from standard input:
Hint: Be sure to flush standard output after writing the prompt.
If the application cannot read from standard input, it terminates without displaying an error. If any I/O errors occur while reading or writing files, the application writes a message to standard error and then continues to process user input.
Examples
Resources
- Sample Input File
- Sample Output File
- Relevant API:
Student Performance and Statistics
Analysis on overall student performance and coverage of requirements