Java: how to get a File from an escaped URL?
Solution 1:
The File
constructor taking an URI
in combination with URL#toURI()
should work:
URL url = getItSomehow();
File file = new File(url.toURI());
Solution 2:
URLDecoder.decode(url);//deprecated
URLDecoder.decode(url, "UTF-8"); //use this instead
See related question How do you unescape URLs in Java?
Solution 3:
AFAIK like this Paths.get(url.toURI()).toFile()
is best, starting with Java 7. See also Converting Java file:// URL to File(...) path, platform independent, including UNC paths.