Я могу загрузить PDF, сделать c и другие форматы, используя приведенный ниже код. Но когда я пытаюсь загрузить файл .msi
из URL-адреса / расположения сервера, я не могу его загрузить, потому что .msi
не может быть преобразован в байт.
try {
URL url=new URL(link);
HttpURLConnection http=(HttpURLConnection)url.openConnection();
double fileSize=(double)http.getContentLengthLong();
BufferedInputStream in=new BufferedInputStream(http.getInputStream());
FileOutputStream fos = new FileOutputStream(this.out);
BufferedOutputStream bout= new BufferedOutputStream(fos,1024);
byte[] buffer= new byte[1024];
double downloaded=0.00;
int read=0;
double percentDownloaded=0.00;
while((read=in.read(buffer,0,1024)) >= 0 )
{
bout.write(buffer,0,read);
downloaded+=read;
percentDownloaded=(downloaded*100)/fileSize;
String percent=String.format("%.4f", percentDownloaded);
System.out.println("Downloaded "+percent+" of file.");
}
bout.close();
in.close();
System.out.println("Download Completed..");
}
catch(IOException ie)
{
ie.printStackTrace();
}
Не могли бы вы мне помочь? чтобы скачать .msi
файл по ссылке через java?