Java Write a program that will only accept input from a file provided as the first command...

70.2K

Verified Solution

Question

Programming

Java

Write a program that will only accept input from a file providedas the first command line argument. If no file is given or the filecannot be opened, simply print “Error opening file!” and stopexecuting.

A valid input file should contain two lines. The first line isany valid string, and the second line should contain a singleinteger.

The program should then print the single character from thestring provided as the first line of input which is at the indexgiven in the second line.

If this cannot be done for any reason, the program should simplyprint “Error reading input!” and stop executing.

Complete your solution to this example in Exercise.java, whichis open to the left. You may use any combination of If-Thenstatements and Try-Catch statements to either prevent exceptionsfrom occurring or catching them when they do occur. Either approachis valid.

Example input:

Testing1237

Here is the correct output for that input:

1

Here’s one more input:

abcd75

and the correct output:

Error reading input!

Answer & Explanation Solved by verified expert
3.8 Ratings (498 Votes)
Thanks for the question Below is the code you will be needing Let me know if you have any doubts or if you need anything to change If you are satisfied with the    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students