Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy this java link checker code does not compile?
    text
    copied!<p>I already read the <a href="https://stackoverflow.com/questions/65515/how-to-find-broken-links-on-a-website">link checker</a> question posted in SO. If there are more questions of this kind and I missed them, my apologies.</p> <p>We need to find broken links in a <a href="http://blog.readytocloud.com" rel="nofollow noreferrer">website</a> in a very easy way and scriptable way, so we can document the links that are broken. I found a <a href="http://unserializableone.blogspot.com/2008/12/link-checker-with-java-better-version.html" rel="nofollow noreferrer">blog post</a> with some code written in java that will do exactly what I need, and my very basic knowledge let me compile it, but I get errors every time. I thought that maybe someone here might be able to direct me to why the code does not compile. </p> <p>Here is the code:</p> <pre><code>import java.net.HttpURLConnection; import java.net.URL; class links { private static boolean isLive(String link) { HttpURLConnection urlConnection = null; try { URL url = new URL(link); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("HEAD"); urlConnection.connect(); String redirectLink = urlConnection.getHeaderField("Location"); if (redirectLink != null &amp;&amp; !url.equals(redirectLink)) { return isLive(redirectLink); } else { return urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK; } } catch (Exception e) { return false; } finally { if (urlConnection != null) { urlConnection.disconnect(); } } } public static void main(String[] args) { System.out.println(isLive("http://www.fakelink.net")); } } </code></pre> <p>Thanks to all that reply. I putting the code that compiles here, for future reference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload