How to use Java program to detect Internet connection
How to write a java program and tell me whether I have Internet access I don't want to Ping or create a connection to an external URL because if the server is going to shut down, my program won't work properly I want a reliable way to detect which will tell me 100% guarantee whether I have an Internet connection, regardless of my operating system I want a computer program that connects directly to the Internet
I have tried the following procedure
URL url = new URL("http://www.xyz.com/"); URLConnection conn = url.openConnection(); conn.connect();
I want something more suitable than this program
Thank you, Sunil Kumar sahoo
Solution
It depends on what your "Internet" connection means Many computers are not directly connected to the Internet, so even if you can check whether they have a network connection, it does not always mean that they can access the Internet
The only 100% reliable way to test whether a computer can access other servers is to actually try