How do I load resource using Class Loader as File?
classloader, file, file-handling, io, java
Solution
To convert a `file://...` URL to `java.io.File`, you'll have to combine both `url.getPath()` and `url.toURI()` for a safe solution:
File f;
try {
f = new File(url.toURI());
} catch(URISyntaxException e) {
f = new File(url.getPath());
}
Full explanations in this blog post.
Problem
I want to open files using the class loader. However I always get a FileNotFoundException. How do I create a new File using the URL? I don't want to open it as a stream just as a file. ``` URL url = VersionUpdater.class.getResource("xslt/screen/foo"); File f = ... ```