PDA

View Full Version : Java Input/Output



hellreaver
03-31-2009, 05:15 PM
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?

hellreaver
04-01-2009, 03:29 AM
Nevermind, I figured it out.

Lpe04
04-01-2009, 03:47 AM
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 ;)

Twey
04-01-2009, 08:47 AM
It would, but a java.util.Stack (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html) would be preferable.