I wrote this this method to download a webpage given a URL. It is designed to download HTML only. If I want to do error checking and allow HTML only how should I do this?
public static String download(URL url) throws IOException {
InputStream is = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String page = "";
String line;
while((line = reader.readLine()) != null){
page = page + line;
}
return page;
}
Originally I was planning on doing this:
String file = url.getFile();
if(file.subString(file.indexOf("."),file.length()-1).equalsIgnoreCase("HTML")){
// do method
However the URL: http://www.smu.com
returns ""
for url.getFile()
. Anyone have any suggestions?