user496949
user496949

Reputation: 86075

How to get the classloader's directory information?

Would like to build the absolutepath use this information. Anyone knows how?

Upvotes: 1

Views: 561

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

Judging by your other question, you are going about this wrong. If you only need to read from the resource, use getClass().getResource() to locate the resource and use it from the URL.

If OTOH the app. might also change the information in the resource, it is best to store a copy of the changed resource on the local file system. Don't store it in the 'user.dir' - which is fragile and unreliable, but a sub-directory (e.g. based on the reverse domain name) of 'user.home'.

Upvotes: 0

MeBigFatGuy
MeBigFatGuy

Reputation: 28568

If you know the name of the resource within the class path, i believe you can call

URL j = loader.getResource(name);

and from the URL you can tell where it is either in the file system, or in what jar it resides.

Upvotes: 1

Related Questions