Check out example codes for "java download file from url". It will help you in understanding the concepts better.

Code Example 1

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}

Code Example 2

public static String URLReader(URL url) throws IOException {
    StringBuilder sb = new StringBuilder();
    String line;
 
    InputStream in = url.openStream();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while ((line = reader.readLine()) != null) {
            sb.append(line).append(System.lineSeparator());
        }
    } finally {
        in.close();
    }
 
    return sb.toString();
}

Code Example 3

InputStream in = new URL(FILE_URL).openStream();Files.copy(in, Paths.get(FILE_NAME), StandardCopyOption.REPLACE_EXISTING);

Learn ReactJs, React Native from akashmittal.com