1
使用HTTPUrlConnection下載文件時有一種方法可以在嘗試恢復文件下載之前檢查服務器是否支持恢復?HTTPUrlConenction檢查服務器是否支持恢復
要麼我做錯了什麼錯誤的服務器不支持簡歷,我怎麼能先檢查?
File file = new File(Environment.getExternalStorageDirectory()+"/dir/", filename);
if (file.exists()) {
crashes here---> //c.setRequestProperty("Range", "Bytes="+(file.length())+"-");
Log.d("file already exists", filename);
}
c.setDoOutput(true);
c.setDoInput(true);
c.connect();
f = new FileOutputStream(new File(PATH_op), true);//set true so if file exists it will append
logcat的
03-17 14:55:23.746: WARN/System.err(11196): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
我發現,如果服務器支持的簡歷,這樣做,我發現了這一點,通過檢查接受,範圍效應初探作爲Nuvaak建議。
我嘗試了你說的和值的確是字節,但是每當我取消註釋行時,我得到一個文件沒有發現異常 – brux 2012-03-17 16:30:41
該異常與'Range'頭文件無關,爲FileOutputStream檢出javadoc以獲取更多關於例外。 http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html#FileOutputStream(java.io.File,布爾值) – neevek 2012-03-17 16:39:54
這意味着file.size()有問題,而不是與你的連接。 – zapl 2012-03-17 16:40:40