开发者

CLASSPATH url format

i'm searching for a path for some resource which is in CLASSPATH. I'm using the method from ClassLoader getResource(String name) and i get URL. From this URL i get a path with method getP开发者_如何学Goath(). The format of that depends on that whether the resorce is in JAR or not. If the resource is in JAR then i get file:/C:/path/lib.jar!/resourceName.resource. If the resource is not in JAR then i get /C:/path/resourceName.resource.

My question is are these path OS independent? When i invoke this code on UNIX JVM do i get this same path format?

Kind regards Sebastian


First: The filename is actually OS independent. Java can handle this fine. Second: Remember your jar might be on the classpath but must not be a file!

You can just use getResourceAsStream(name) so you don't have to care about this at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜