Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (use the try block to check if the input file exists) and read the contents line by line. It should also open the output file as a text file and write to it the lines in the input file, prefixed by line numbers starting at 1.   So if an input file named "fred.txt" contains: Hello, I am Fred. I am enrolled in a class. Bye   and the user enters "fred.txt" and "fredNum.txt", then after running the program "fredNum.txt" will contain something like: 1 Hello, 2 3 I am Fred. 4 I am enrolled in a class. 5 6 Bye   Finally, the program should display on the screen your name, the name of the output file, followed by a count of the total number of lines, the total number of words, and the total number of characters in the input file. For the above input file, the following will be displayed to the screen: My name = Joe Bloggs Name of Output file = fredNum.txt Total number of lines in fred.txt = 6 Total number of words in fred.txt = 10 Total number of characters in fred.txt = 43

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a Java program to perform the following tasks:

The program should ask the user for the name of an input file and the name of

an output file. It should then open the input file as a text file (use the try block

to check if the input file exists) and read the contents line by line. It should

also open the output file as a text file and write to it the lines in the input file,

prefixed by line numbers starting at 1.

 

So if an input file named "fred.txt" contains:

Hello,

I am Fred.

I am enrolled in a class.

Bye

 

and the user enters "fred.txt" and "fredNum.txt", then after running the

program "fredNum.txt" will contain something like:

1 Hello,

2

3 I am Fred.

4 I am enrolled in a class.

5

6 Bye

 

Finally, the program should display on the screen your name, the name of the

output file, followed by a count of the total number of lines, the total number

of words, and the total number of characters in the input file.

For the above input file, the following will be displayed to the screen:

My name = Joe Bloggs

Name of Output file = fredNum.txt

Total number of lines in fred.txt = 6

Total number of words in fred.txt = 10

Total number of characters in fred.txt = 43

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education