Results 1 to 4 of 4

Thread: Java Input/Output

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  2. #2
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nevermind, I figured it out.

  3. #3
    Join Date
    Mar 2009
    Location
    Florida
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    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

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It would, but a java.util.Stack would be preferable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •