Question
Create a new java class named ReadingTestLab and a txt file with some text. 1. Add a main method. 2. Add code in the main
Create a new java class named ReadingTestLab and a txt file with some text.
1. Add a main method.
2. Add code in the main method that will:
- Check to see if there is one command line argument.
- If there is not just one argument then the method will output: Please enter one argument on the command line and terminate.
- If there is one command line argument then the method will call the run method and pass the argument.
3. Add a method named run.
- The method will have a void return type.
- The method will have one String parameter.
4. Add code in the run method that will:
- Open the input file that was passed as a parameter and output the full contents to the terminal window. To accomplish this the method will need to:
- Open the input file.
- Loop through the lines of the input file.
- Output each line.
- Close the input file after the loop has run.
- Include full exception handling.
The class must pass the lab 4 tests.
Verify the class runs properly.
Pass in a file name that exists and verify the file was properly read and displayed.
Verify your error handling, too! What happens if you do not pass in file name? What if you pass in a file name that does not exist?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started