Question: Problem 2 : File Head Display Write a program that asks for the name of a file ( you can use the MyFriends.txt file attached

Problem 2: File Head Display
Write a program that asks for the name of a file (you can use the MyFriends.txt file attached below. It needs to be added to your project folder in your IntelliJ project).
a) The program should display the first five lines of the file (or the entire contents, if the file has less than five lines).
b) The program should write the first five lines to a new file.
Remember, files can have fewer then five lines. Make sure your program will not crash if given a file with less than five lines.

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!