Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rexuiz.checksite;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class URLUtils {
- public static void main(String[] args) {
- System.out.println(URLUtils.checkIfURLExists("http://108.61.164.188/RexuizLauncher/"));
- }
- public static boolean checkIfURLExists(String targetUrl) {
- HttpURLConnection httpUrlConn;
- try {
- httpUrlConn = (HttpURLConnection) new URL(targetUrl).openConnection();
- httpUrlConn.setRequestMethod("HEAD");
- httpUrlConn.setConnectTimeout(30000);
- httpUrlConn.setReadTimeout(30000);
- return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);
- } catch (Exception e) {
- System.out.println("Error: " + e.getMessage());
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement