Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何检查java中是否存在互联网连接?
我有一个连接到在线文档的 java 桌面应用程序。现在我如何确定用户是否连接到互联网。
尝试从 Internet 检索某些内容。就像文件一样。或谷歌。或者ping什么东西。
您可能想要设置一个合理的超时时间,或者在启动时检查后台线程(尽管连接可能会改变,但显示一个小的“已连接”图标或其他东西会很好)。
只是 ping 一些知名的网络资源