0

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;
    }
user18333852
  • 45
  • 1
  • 1
  • 6

1 Answers1

0

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-

user18333852
  • 45
  • 1
  • 1
  • 6