Question: File/IO Create a program that prints out the last five lines in a text file to the console. For example, a text file may contain

File/IO

Create a program that prints out the last five lines in a text file to the console.

For example, a text file may contain the following text:

(original.txt)

1. All work and no play makes Jill a dull girl

2. All work and no play makes Jack a dull boy

3. All work and no play makes Jill a dull girl

4. All work and no play makes Jack a dull boy

5. All work and no play makes Jill a dull girl

6. All work and no play makes Jack a dull boy

7. All work and no play makes Jill a dull girl

8. All work and no play makes Jack a dull boy

9. All work and no play makes Jill a dull girl

10. All work and no play makes Jack a dull boy

Your program will print the following:

6. All work and no play makes Jack a dull boy

7. All work and no play makes Jill a dull girl

8. All work and no play makes Jack a dull boy

9. All work and no play makes Jill a dull girl

10. All work and no play makes Jack a dull boy

Notice that the last five lines are printed. The most efficient way to solve this problem is to keep track of fives lines of text in an ArrayList (or array) and print it out once you reach the end of the file. You may use any other approach to solve this problem but it will result in a deduction of 10 points. Also, you cannot store all the text in the ArrayList or read the text twice (-10 point deduction for each).

Please turn in the file Tail.java which contains your solution.

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!