Newer
Older
KA-Visual / src / mainClass.java
Jonathan Ström on 21 Feb 2017 894 bytes Added download URL function.
import java.net.MalformedURLException;
import java.net.URL;

import java.io.*;

public class mainClass {
	public static void main(String[] args) {
		getUrl("http://kryssakuten.se");
	}
	
	public static void getUrl(String urlString) {
		URL url;
	    InputStream is = null;
	    BufferedReader br;
	    String line;

	    try {
	        url = new URL(urlString);
	        is = url.openStream();  // throws an IOException
	        br = new BufferedReader(new InputStreamReader(is));

	        while ((line = br.readLine()) != null) {
	            System.out.println(line);
	        }
	    } catch (MalformedURLException mue) {
	         mue.printStackTrace();
	    } catch (IOException ioe) {
	         ioe.printStackTrace();
	    } finally {
	        try {
	            if (is != null) is.close();
	        } catch (IOException ioe) {
	            // nothing to see here
	        }
	    }  
	}
}