java检测网络连接状态

java检测网络连接状态
http://rabby.iteye.com/blog/807126
public static void main(String[] args) {
		URL url = null;
		try {
			url = new URL("http://baidu.com");
			try {
				InputStream in = url.openStream();
				in.close();
				System.out.println("网络连接正常!");
			} catch (IOException e) {
				System.out.println("网络连接失败!");
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

猜你喜欢

转载自macleo.iteye.com/blog/1621413