Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Passing links from a file (java)

  • 23-04-2010 01:43PM
    #1
    Registered Users, Registered Users 2 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, Paid Member Posts: 2,692 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