如何将 https url 转换为 Java 中的文件?
How to convert https url to File in Java?
我有一个字符串格式的 https url。如何将其转换为文件?我试过了,但出现错误 - 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;
}
FileUtils.copyURLToFile
对我来说效果很好。
我有一个字符串格式的 https url。如何将其转换为文件?我试过了,但出现错误 - 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;
}
FileUtils.copyURLToFile
对我来说效果很好。