'How to convert https url to File in Java?

I have an https url which is of String format. How can I convert it to File? I tried this but I'm getting error - URI scheme is not "file"

 public static File convertURLToFile(String strURL) throws MalformedURLException {
        URL url = new URL(strURL);
        File file;
        try {
            file = new File(url.toURI());
        } catch (URISyntaxException e) {
            String message = "Error in converting url to file";
            throw new RuntimeException(message, e);
        }
        return file;
    }


Solution 1:[1]

FileUtils.copyURLToFile worked well for me.

Reference - https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#copyURLToFile-java.net.URL-java.io.File-

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user18333852