Classpath URI

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

How can I get a URI for an arbitrary file that is known to be
somewhere on the classpath? I don't want to specify either an
absolute or relative path to the file.
 
K

Knute Johnson

Christopher said:
How can I get a URI for an arbitrary file that is known to be
somewhere on the classpath? I don't want to specify either an
absolute or relative path to the file.

See File and its toURI() method.
 
O

Owen Jacobson

L

Lew

Owen said:
Use one of the "getResource" methods:
<http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourc...)>
<http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getR...)>

There are also matching getResourceAsStream methods that will open them for you.

One assumes that the OP wants URLs and not URNs. Were it only needed
to have a URN, the OP could prefix the FQN with an arbitrary scheme,
e.g., "fqn:com.lewscanon.foo.Foo". That would fulfill the OP's
request for a means to obtain a URI literally, if not usefully.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top