yegor256
yegor256

Reputation: 105043

How can I find the file containing a specific class somewhere in my classpath?

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

Answers (2)

Gursel Koca
Gursel Koca

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

Peter Lawrey
Peter Lawrey

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

Related Questions