Код: Выделить всё
public static void downloadFile(String fileURL, String destination) throws IOException {
URL url = new URL(fileURL);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
int responseCode = httpConn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = httpConn.getInputStream();
FileOutputStream outputStream = new FileOutputStream(destination);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
} else {
throw new IOException("No file to download. Server replied with HTTP code: " + responseCode);
}
httpConn.disconnect();
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ork-interr