サンプル
import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] args) { System.out.println("Result : " + ping("https://blogs.yahoo.co.jp/dk521123/34842155.html", 1000)); } public static boolean ping(String url, int timeout) { try { URL targetUrl = new URL(url); HttpURLConnection connection = (HttpURLConnection) targetUrl.openConnection(); connection.setConnectTimeout(timeout); connection.setReadTimeout(timeout); connection.setRequestMethod("HEAD"); int responseCode = connection.getResponseCode(); return (HttpURLConnection.HTTP_OK <= responseCode && responseCode <= 399); } catch (IOException exception) { return false; } } }