Skip to content

Commit 400a336

Browse files
URL status checker.java
1 parent e0bf8da commit 400a336

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

URL status checker.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.net.*;
2+
3+
public class URLChecker {
4+
public static void main(String[] args) {
5+
try {
6+
URL u = new URL("https://www.google.com");
7+
HttpURLConnection h = (HttpURLConnection) u.openConnection();
8+
h.setRequestMethod("GET");
9+
int code = h.getResponseCode();
10+
11+
System.out.println("Status Code: " + code);
12+
} catch (Exception e) {
13+
System.out.println("Invalid URL!");
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)