我在从“HTTPS URL”下载文件(大小超过 200mb)时遇到问题。 问题还与认证和下载问题有关。我也使用了 TrustManager 、SSL security 等代码。但问题仍然存在,主要是因为我无法通过证书。
例如:我的 HTTPS URL 是:- https://v1/xyz/abc.avi
。现在我想下载这个文件但无法下载。正在从我的应用程序的以下代码下载小文件:-
.....if (contentLength > 0) {
try {
InputStream in = urlConn.getInputStream();
while ( (ch = in.read()) != -1) {
rec.append((char)ch);
}
} ....
请帮助。
最佳答案
尝试使用以下代码下载:
private void downloadFile() throws Exception {
URL fileUrl = new URL("https://.....");
URLConnection urlConnection = fileUrl.openConnection();
BufferedInputStream bufferedInputStream = new BufferedInputStream(urlConnection.getInputStream());
FileOutputStream fos = new FileOutputStream("c:/file.avi");
BufferedOutputStream dest = new BufferedOutputStream(fos);
int count;
byte data[] = new byte[2048];
while((count = bufferedInputStream.read(data)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
关于从 HTTPS URL 下载大文件中的 Java 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20786568/