简体   繁体   English

JavaSE 7 URL超时在JavaSE 6中有效吗?

[英]JavaSE 7 URL Timing out that works in JavaSE 6?

The following code works fine in JavaSE 6 but is throwing a ConnectException (timeout) when executed in JavaSE 7. Is this a JDK7 bug or bad code? 以下代码在JavaSE 6中工作正常,但是在JavaSE 7中执行时抛出ConnectException(超时)。这是JDK7错误还是错误代码? I really don't understand... 我真的不明白

   public static void main(String[] args) {
    try {
        URL url = new URL("http://dl.dropbox.com/u/34206572/version.txt");
        url.openConnection().connect();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }

I tried this code in 1.7.0_02-b13, it works fine. 我在1.7.0_02-b13中尝试了此代码,效果很好。 I visit the link above, it is not available (page 404 is returned). 我访问了上面的链接,但该链接不可用(返回了页面404)。

Maybe, you mean that the following code crashes: 也许,您的意思是以下代码崩溃:

public static void main(String[] args) throws Exception  {
    URL url = new URL("http://dl.dropbox.com/u/34206572/version.txt");
    URLConnection conn = url.openConnection(); 

    InputStream inputStream = conn.getInputStream();             
}

with following exception (I formatted it out): 有以下异常(我将其格式化):

Exception in thread "main" java.io.FileNotFoundException: 
                  http://dl.dropbox.com/u/34206572/version.txt
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(
                                    HttpURLConnection.java:1610)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM