如何编写一个java程序,告诉我我是否可以上网。 我不想ping或创建与某些外部URL的连接,因为如果该服务器将关闭,那么我的程序将无法工作。 我想要可靠的方法来检测哪些信息会告诉我100%保证无论我的操作系统是否具有互联网连接。 我想要直接连接到互联网的计算机的程序。
我已经尝试过下面的程序
URL url = new URL("http://www.xyz.com/"); URLConnection conn = url.openConnection(); conn.connect();我想要比这个程序更适合的东西
感谢Sunil Kumar Sahoo
How to write a java program which will tell me whether I have internet access or not. I donot want to ping or create connection with some external url because if that server will be down then my program will not work. I want reliable way to detect which will tell me 100% guarantee that whether I have internet connection or not irrespective of my Operating System. I want the program for the computers who are directly connected to internet.
I have tried with the below program
URL url = new URL("http://www.xyz.com/"); URLConnection conn = url.openConnection(); conn.connect();I want something more appropriate than this program
Thanks Sunil Kumar Sahoo
最满意答案
这取决于你的意思是“互联网”连接。 许多计算机没有直接连接到互联网,所以即使你可以检查他们是否有网络连接,这并不意味着他们可以访问互联网 。
测试计算机是否可以访问其他服务器的唯一100%可靠方法是实际尝试。
It depends on what you mean by "internet" connection. Many computers are not connected directly to the internet, so even if you could check whether they have a network connection, it doesn't always mean they can access the internet.
The only 100% reliable way to test whether the computer can access some other server is to actually try.
更多推荐
发布评论