From e7f0fd4ac9f29236bcc6182e5db37b16ee42a5ef Mon Sep 17 00:00:00 2001 From: bigheadbh Date: Tue, 18 Aug 2020 08:51:46 -0300 Subject: [PATCH] new files! --- ajuda/java/ExemploURL.java | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ajuda/java/ExemploURL.java diff --git a/ajuda/java/ExemploURL.java b/ajuda/java/ExemploURL.java new file mode 100644 index 0000000..b21b213 --- /dev/null +++ b/ajuda/java/ExemploURL.java @@ -0,0 +1,40 @@ +import java.io.*; +import java.net.*; + +class ExemploURL { + public static String getHtml(String endereco){ + URL url; + InputStream is = null; + BufferedReader br; + String resp = "", line; + + try { + url = new URL(endereco); + is = url.openStream(); // throws an IOException + br = new BufferedReader(new InputStreamReader(is)); + + while ((line = br.readLine()) != null) { + resp += line + "\n"; + } + } catch (MalformedURLException mue) { + mue.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + + try { + is.close(); + } catch (IOException ioe) { + // nothing to see here + + } + + return resp; + } + public static void main(String[] args) { + String endereco, html; + endereco = "http://maratona.crc.pucminas.br/series/Friends.html"; + html = getHtml(endereco); + System.out.print(html); + } +}