Question: Develop a program to perform file operations such as writing. appending, and reading from a text file. The program should first write a predefined string

Develop a program to perform file operations such as writing. appending, and reading from a text file. The program should first write a predefined string to a file, then append a userprovided string to the same file, and finally read and print the contents of the file.
Writing to a File:
The program should create or overwrite a file named source.txt.
It should write the string "Hello World" to the file.
Appending to a File:
The program should prompt the user to input a string.
This user-provided string should be appended to the existing contents of source.txt.
Reading from a File:
After appending the string, the program should read all contents of source.txt.
It should print the contents of the file line by line to the console.
Instructions:
The solution code should have its class name as AppendToFile.
The main logic for the solution should be written inside AppendToFile class.
Input format :
The input consists of a string.
Output format:
The output prints the string "Hello World" with the appended string.
Refer to the sample output for formatting specifications.
Sample test cases :
Input 1:
Live Like Laugh
Input 2:
Alice in Wonderland
Output 1 :
Hello World
Live Lile Laugh
Output 2:
Hello World
Alice in Wonderland
Input 3 :
Output 3 :
Actions Speak Louder Than W Hello World
Actions Speak Louder Than WI
 Develop a program to perform file operations such as writing. appending,

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!