【发布时间】:2013-06-05 14:53:04
【问题描述】:
我在从 url 下载 zip 文件时遇到问题。 它适用于 Firefox,但在我的应用中我有 404。
这是我的代码
URL url = new URL(reportInfo.getURI().toString());
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// Check for errors
int responseCode = con.getResponseCode();
InputStream inputStream;
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
OutputStream output = new FileOutputStream("test.zip");
// Process the response
BufferedReader reader;
String line = null;
reader = new BufferedReader(new InputStreamReader(inputStream));
while ((line = reader.readLine()) != null) {
output.write(line.getBytes());
}
output.close();
inputStream.close();
有什么想法吗?
【问题讨论】:
-
你不应该用
reportInfo.getURI().toString()创建一个URL,使用reportInfo.getURI().toURL()