forked from icei-pucminas/aeds2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExemploURL.java
40 lines (34 loc) · 966 Bytes
/
ExemploURL.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}
}