Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Passing links from a file (java)

Options
  • 23-04-2010 1:43pm
    #1
    Registered Users Posts: 4,257 ✭✭✭


    Hi,

    In a bit of a pickle at the moment, I'm doing a project which requires me to
    • Input a web link
    • download it's contents to file
    • parse the content for all sites the site links to
    • check each link individually to see if they are dead or alive, if dead return the response code

    I have 1-3 done however one of the they are separate classes and I cant figure out how to get each link to pass to my checker class one by one.

    Obviously I am not looking for a straight answer (I know how it works here!) but a nudge in the right direction would be great.

    The 1st class downloads the links to a .txt file and they are displayed line by line like so:


    http://boards.ie/vbulletin/newthread.php?do=newthread&f=25
    https://mail.google.com/mail/
    http://www.daft.ie/



    In another class I can check one link for the response code....

    if(
    res.getResponseCode() == HttpURLConnection.HTTP_OK)
    System.out.println("Connection is good Roger");
    else
    System.out.println("There were two Crabs, they work in pairs \n and the response code is \t"+res.getResponseCode());


    Thanks.


Comments

  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,646 Mod ✭✭✭✭TrueDub


    Rather than putting the links out to a text file, why don't you define a method on your checking class that accepts a URL, then performs the check and passes back a success or failure message?

    something like
    public String checkLink(URL url) {
    
    }
    

    which you call in your controlling class.


Advertisement