-
Java Input/Output
I need to create a Java application that reads lines of text from an input file, infile.txt and copies those lines of text in reverse order to an output file, outfile.txt. I have to use a recursive procedure for reading from the input file and writing to the ouput file.
Given the following input data:
The woods are lovely, dark, and deep,
But I have promises to keep,
And miles to go before I sleep.
And miles to go before I sleep.
the output file should contain:
And miles to go before I sleep.
And miles to go before I sleep.
But I have promises to keep,
The woods are lovely, dark, and deep,
I can set the program up to read the input file, as well as to create the output file, but I am not sure how to reverse the order of the lines... any ideas?
-
Nevermind, I figured it out.
-
I was going to say, you could store each line in an array and then count down backwards :) I'm assuming this would work in Java ;)
-
It would, but a java.util.Stack would be preferable.