Finding the broken links in a webpage using Selenium

public class Broken
{
public static void main(String[] args) throws Exception
{
WebDriver driver=new FirefoxDriver();
driver.get("
http://seleniumsubbu.blogspot.in//");
List<WebElement> ele=driver.findElements(By.tagName("a"));
for(int i=0;i<ele.size();i++)
{
int statusCode=0;
try
{
statusCode=getResponseCode(ele.get(i).getAttribute("href"));
}catch(Exception e)
{
e.printStackTrace();
}
if(statusCode==404)
{
System.out.println("INVALIDLINKS :-> "+ele.get(i).getAttribute("href"));
}
}
}
public static int getResponseCode(String urlString) throws IOException{
URL u = new URL(urlString);
HttpURLConnection h = (HttpURLConnection) u.openConnection();
h.setRequestMethod("GET");
h.connect();
return h.getResponseCode();
}
}