我收到連接超時:在java代碼中連接異常請參閱下面。 我已經在谷歌搜索,但沒有得到太多的幫助,你可以在你的機器上運行這個代碼,下面給出了它的完整代碼。 代碼 -獲取連接超時:連接
public class download {
// final static int size=1024;
public static void downloadValuationPDFReport() {
OutputStream outStream = null;
URLConnection uCon = null;
InputStream is = null;
String fAddress = null;
URL Url = null;
String localFileName = "abc.zip";
String destinationDir = "H:\\";//"C:\\Users\\501301605\\Downloads";
try {
fAddress = "http://www.novell.com/coolsolutions/tools/downloads/ntradping.zip";
byte[] buf;
int byteRead = 0;
Url = new URL(fAddress);
outStream = new BufferedOutputStream(new FileOutputStream(destinationDir + "\\" + localFileName));
uCon = Url.openConnection();
is = uCon.getInputStream();
buf = new byte[1024];
while ((byteRead = is.read(buf)) != -1) {
outStream.write(buf, 0, byteRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
你可以嘗試設置一些連接超時: UCON .setConnectTimeout(VALUE); uCon.setReadTimeout(VALUE); –
@SaqibRezwan感謝您的評論,但得到同樣的問題 – RSingh
適合我的作品。防火牆問題?你能直接從瀏覽器下載文件嗎? – agad