package com.ms.biz.test;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class DownloadFileTest {
    public static void downloadFile(String fileURL, String localFilename) throws IOException {
        URL url = new URL(fileURL);
        URLConnection connection = url.openConnection();
        try (InputStream inputStream = new BufferedInputStream(connection.getInputStream()); FileOutputStream outputStream = new FileOutputStream(localFilename)) {
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer, 0, 1024)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
        }
    }

    public static void main(String[] args) {
        String fileURL = "";
        String localFilename = "downloaded_file.txt";
        try {
            downloadFile(fileURL, localFilename);
            System.out.println("File downloaded successfully!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
