Download a File From an URL in Java | Baeldung

PHOTO EMBED

Tue Apr 19 2022 08:37:59 GMT+0000 (Coordinated Universal Time)

Saved by @iwok

try (BufferedInputStream in = new BufferedInputStream(new URL(FILE_URL).openStream());
  FileOutputStream fileOutputStream = new FileOutputStream(FILE_NAME)) {
    byte dataBuffer[] = new byte[1024];
    int bytesRead;
    while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
        fileOutputStream.write(dataBuffer, 0, bytesRead);
    }
} catch (IOException e) {
    // handle exception
}
content_copyCOPY

https://www.baeldung.com/java-download-file