forked from davidjava1991/java17CompleteCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.java
More file actions
32 lines (28 loc) · 852 Bytes
/
Copy pathExample1.java
File metadata and controls
32 lines (28 loc) · 852 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
25
26
27
28
29
30
31
32
package com.david.class156;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Example1{
public static void main(String[] args) {
try {
URL url = new url("https://www.google.com");
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String response = "";
System.out.println("response of URL: ");
while((response = br.readLine()) != null) {
System.out.println(response);
}
br.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}