公司是用代理上网的,使用url.openConnection()的时候一直报连接超时的exception,我自己试了上网又是可以的,后来发现原来是使用代理的缘故。 public class Test ...{ public static void main(String[] args) throws Exception ...{ //设置这三个属性以后就可以进行正常的连接了 System.setProperty("proxySet", "true"); System.setProperty("proxyHost", "172.31.1.246"); System.setProperty("proxyPort", "8080"); URL url = new URL("http://www.baidu.com/index.html"); URLConnection con = url.openConnection(); con.connect(); System.out.println(con.getInputStream()); }}