import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; class Program01 { InputStreamReader stream = null; BufferedReader reader = null; public void getWebpage() { try { tryGetWebpage(); }catch(MalformedURLException e) { System.out.println("Hibás URL"); }catch(IOException e) { System.out.println("Hiba a kapcsolatban"); }finally { try{ reader.close(); stream.close(); }catch(IOException e){} } } public void tryGetWebpage() throws MalformedURLException, IOException { URL url = new URL("http://szit.hu"); URLConnection con = url.openConnection(); stream = new InputStreamReader(con.getInputStream()); reader = new BufferedReader(stream); System.out.println(reader.readLine()); System.out.println(reader.readLine()); for (String line = reader.readLine(); line != null; line = reader.readLine()) { System.out.println(line); } } public static void main(String args[]) { Program01 program01 = new Program01(); program01.getWebpage(); } }