Created
January 12, 2016 13:31
-
-
Save Moddus/f3daff49031fba6dfb1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static File getFile(String name) { | |
URL url = Thread.currentThread().getContextClassLoader().getResource(name.replace(File.separatorChar, '/')); | |
if(url != null) { | |
try { | |
return new File(url.toURI()); | |
} catch (Exception var3) { | |
throw new RuntimeException("Resource was found on classpath, but cannot be resolved to a normal file (maybe it is part of a JAR file): " + name); | |
} | |
} else { | |
File file = new File(name); | |
if(file.exists()) { | |
return file; | |
} else { | |
throw new RuntimeException("Cannot find resource in classpath or in file-system (relative to CWD): " + name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment