Results 1 to 2 of 2
  1. #1
    luxurymode is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default reading lines from URL and printing backwards

    I want to write a simple program that reads the first five lines of a URL and then prints them out in reverse order, so it'd be line 5, line 4, line 3, line 2, line 1.

    Here's what I've got so far:

    Java Code:
    public static void main(String[] arg) throws Exception {
        BufferedReader keyboard;
        String inputLine;
        keyboard = new BufferedReader(new InputStreamReader(;
        System.out.print("Please enter the name of a company (without spaces): ");
        System.out.flush();        /* Make sure the line is printed immediately. */
        inputLine = keyboard.readLine();
        URL u = new URL("http://www." + inputLine + ".com/");
        InputStream ins = u.openStream();
        InputStreamReader isr = new InputStreamReader(ins);
        BufferedReader readURL = new BufferedReader(isr);
    What would be the most elegant way to do what I'm trying to do?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Read the lines into a list and loop over the list backwards after the reading is finished, of course.

Similar Threads

  1. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 09:17 AM
  2. Two '\n' characters between lines while reading File
    By subith86 in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 09:56 AM
  3. problem reading a files lines
    By j187 in forum New To Java
    Replies: 1
    Last Post: 12-17-2010, 12:43 AM
  4. inputting and writing a file backwards
    By jigglywiggly in forum New To Java
    Replies: 0
    Last Post: 03-18-2009, 07:24 PM
  5. Reading specific lines
    By ivvgangadhar in forum New To Java
    Replies: 8
    Last Post: 01-12-2009, 08:53 AM

Posting Permissions

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