diff --git a/src/mainClass.java b/src/mainClass.java index eeb68cf..35e23d7 100644 --- a/src/mainClass.java +++ b/src/mainClass.java @@ -1,5 +1,37 @@ +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 + } + } } } \ No newline at end of file