Write a Java program. 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 (if the input file
does not exist it should throw an exception) 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 enrolled in JT179.
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 enrolled in JT179.
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
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- write java programarrow_forwardWrite a program (in Java or C++), allowing to: • Create a folder "Main" • Create a file in the folder "File1" Add Read, Write permissions to "File1" Write in "File1" ● ● Read the content of "File1" ● Modify the content of "File1" Remove the Write permission of "File1" Try to write again in "File1" ● A screenshot is needed showing the results of the program execution.arrow_forwardPlease write a Java program , to write data into a file ( output.txt ). The output.txt file is below. 1 22 333 4444 55555 666666arrow_forward
- can you do it pythonarrow_forwardIn Java Suppose you are given a text file that contains the names of people. Every name inthe file consists of a first name and a last name. Unfortunately, the programmer thatcreated the file of names had a strange sense of humor and did not guarantee thateach name was on a single line of the file. Write a program that reads this file ofnames and writes them to the console, one name per line.For example, if the input file (Names.txt) contains:Bob Jones FredCharles EdMarstonJeffWilliamsThe output should be:Bob JonesFred CharlesEd MarstonJeff Williams Sample Output:Enter the name of the input file:Names.txtBob JonesFred CharlesEd MarstonJeff WilliamsFile processing completed.arrow_forwardWrite a C++ program using classes that readslines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the filecannot be opened, print the message “File couldn’t be opened”, followed by a space and the filename, and exit. The program should keep track of the number of lines, the number of non-blank lines, the number of words, and the number of integers read from the file.arrow_forward
- in java Integer cradleQuantity and string friendName are read from input. A FileOutputStream named fileStream is declared and the file named cradle.txt is opened. Then, a PrintWriter named cradleWriter is declared and associated with the file. Write the following to the opened file: "Remember:" "* * * *" cradleQuantity, followed by " cradles for " and friendName Another "* * * *" End each output with a newline. Finally, close the file. Ex: If the input is 12 Dax, then cradle.txt contains: Remember: * * * * 12 cradles for Dax * * * * Note: Data written to a file may be lost if the file is not closed. 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public class FileOutput { publicstaticvoidmain(String[] args) throwsIOException { Scannerscnr=newScanner(System.in); FileOutputStreamfileStream=null; PrintWritercradleWriter=null; intcradleQuantity; StringfriendName; cradleQuantity=scnr.nextInt(); friendName=scnr.next();…arrow_forwardJava Your program must read a file called personin.txt. Each line of the file will be a person's name, the time they arrived at the professor's office, and the amount of time they want to meet with the professor. These entries will be sorted by the time the person arrived. Your program must then print out a schedule for the day, printing each person's arrival, and printing when each person goes in to meet with the professor. You need to print the events in order of the time they happen. In other words, your output will be sorted by the arrival times and the times the person goes into the professor's office. In your output you need to print out a schedule. In the schedule, new students go to the end of the line. Whenever the professor is free, the professor will either meet with the first person in line, or meet with the first person in line if nobody is waiting. Assume no two people arrive at the same time. You should solve this problem using a stack and a queue. You can only…arrow_forwardWrite a Python program that reads a text file called student.txt. The input text file contains student_ID, student_name, Quiz_grade as well as Test_grade for each student. Your program should read each student details from the file Then calculate the average of Quizzes and Tests marks Display the students’ details: Total number of students, total average, the total highest and lowest marks. The program should output the report into a file called output.txt. A sample of output text file is given below.arrow_forward
- Write a C program that reads a text file "My_book.txt" and counts the number of characters, words, and lines in the file. Then, the program should write these counts to a new file "My_book_info.txt" in the following format: Number of characters: [count] Number of words: [count] Number of lines: [count]arrow_forwardurgent plzarrow_forwardWrite a Python program for a simple quiz game. The questions and answers are stored in a text file named "questions.txt." Each line in the file represents a question and its corresponding options and correct answer in the format: "Question, Option1, Option2, Option3, Option4, CorrectOption." The program should load the questions from the file, present them to the user one by one, and keep track of their score. Allow the user to input their answer, and after completing the quiz, display their final score. Make sure to handle cases where "questions.txt" does not exist or has incorrect formatting. Use functions to structure your code, making it easier to understand and maintain. You can use a list or dictionary to store the questions and options. Ex: questions.txt: What is the capital of France?, Berlin, London, Paris, Madrid, 3 Who is the author of "To Kill a Mockingbird"?, Mark Twain, Harper Lee, J.K. Rowling, Ernest Hemingway, 2 What is the largest mammal on Earth?, Elephant, Blue…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education