1
我使用這種方式超時下載文件
URL url = new URL(URL)
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setConnectTimeout(TimeOut);
connection.setReadTimeout(TimeOut);
connection.connect();
String status = connection.getHeaderField(0);
我想要做的是,如果該文件未在指定時間下載,然後 下載文件停止下載或給超時異常。
我有setConnectTimeout()
,但只有在初始連接時間內沒有建立連接 時纔會發生異常。