Question: Please Use Java to answer the following quesiton: For each of the questions you need to write your approach. Else 50% points will be deducted.

Please Use Java to answer the following quesiton:

For each of the questions you need to write your approach. Else 50% points will be deducted.

For each of the following, you need to write the program and run the program.

The best way would be to run the program and copy the code in the pdf.

Insert the screen-shot of the output in the pdf file, in which you are writing the program. This carries major points. (30% of the points for each question)

For the question 1,2,4,5 you also need to provide the input files on which you have tested.

1. Write a program that will count the number of lines in each file that is specified on the command line. Assume that the files are text files. Note that multiple files can be specified, as in

a. java LineCounts fileA.txt fileB.txt fileC.txt

b. Write each file name, along with the number of lines in that file, to the standard output. If an error occurs while trying to read from one of the files, you should print an error message for that file, but you should still process all the remaining files. Use Scanner, a BufferedReader, or a TextReader to process each file.

c. Eg:- Let us say, you have three files in the current directory. Say A.txt, B.txt, C.txt. Each of the files has 20, 30, 40 lines respectively Now you ran your program with the following input. java LineCounts A.txt D.txt C.txt on the command line. The output is as follows:- A.txt 20 Error!! Unable to read that file. C.txt 40

d. You should catch the exception, if you are unable to read a file using the exception handler. Only then you get the points.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!