How to get the classloader's directory information?
Would like to build the 开发者_开发百科absolutepath use this information. Anyone knows how?
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.
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'.
精彩评论