线程“main”中的异常java.net.ConnectException:连接超时:connect

时间:2015-01-07 11:00:42

标签: java

我正在尝试使用URL读取HTML文件。但是要获得超时的例外。

源代码:

import java.net.*;
import java.io.*;

public class URLReader {
    public static void main(String[] args) throws Exception {
        System.setProperty("java.net.useSystemProxies","true");
        URL oracle = new URL("http://www.oracle.com/");
        URLConnection yc = oracle.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                                    yc.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);
        in.close();
    }
}

1 个答案:

答案 0 :(得分:0)

此代码适用于我,请检查您的互联网连接..