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? 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. I visit the link above, it is not available (page 404 is returned).
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.