-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathURLinstance.java
More file actions
24 lines (21 loc) · 822 Bytes
/
URLinstance.java
File metadata and controls
24 lines (21 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// A simply way of accessing a server is to use the URLConnection class.
// This class represents a connection between an applicant and a URL instance.
// A URL represents a resource on the internet.
import java.io.*;
import java.net.*;
public class URLinstance {
public static void main(String[] args) {
try {
URL url = new URL("http://www.google.com");
URLConnection urlconnection = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
} catch (IOException e) {
System.out.println(e);
}
}
}