-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (30 loc) · 1.29 KB
/
Copy pathMain.java
File metadata and controls
44 lines (30 loc) · 1.29 KB
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
41
42
43
44
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String[] args) {
//we are using a high level API and hence don't need to use any socket and stuff
try {
URL url = new URL("http://example.org");
//instead of doing this directly we can do the below also
BufferedReader inputStream = new BufferedReader(new InputStreamReader(url.openStream()));
// //this will return an instance of the class
// URLConnection urlConnection = url.openConnection();
// //you can now set any values you want of the connection b4 opening the connection
// urlConnection.setDoOutput(true);
// //opening connection
// urlConnection.connect();
// BufferedReader inputStream = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line="";
while(line!=null){
line= inputStream.readLine();
System.out.println(line);
}
inputStream.close();
}catch (IOException e){
System.out.println("Error in IO : "+e.getMessage());
}
}
}