Reputation: 105043
I'm trying to find a single file in classpath. This file is somewhere in one of JARs available in classpath. I'm sure that this task is rather typical. Is there any utility for this?
Upvotes: 0
Views: 134
Reputation: 21280
You can use this class, it looks for class files, but you can easily modify to look for all kind of files.
Upvotes: 1
Reputation: 533442
Try
URL url = getClass().getClassLoader().getReource("name");
or
InputStream is = getClass().getClassLoader().getResourceAsStream("name");
Combined with IOUtils
String text = IOUtils.toString(is);
byte[] bytes = IOUtils.toByteArray(is);
Upvotes: 4