Answers for "how to check internet is working or not in java"

0

how to check internet is working or not in java

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Tester {
   public static void main(String[] args) {
      try {
         URL url = new URL("http://www.google.com");
         URLConnection connection = url.openConnection();
         connection.connect();
         System.out.println("Internet is connected");
      } catch (MalformedURLException e) {
         System.out.println("Internet is not connected");
      } catch (IOException e) {
         System.out.println("Internet is not connected");
      }
   }
}
Posted by: Guest on May-02-2020

Code answers related to "how to check internet is working or not in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language