开发者

How to access files in other packages without using a dummy class

I am actually loading OWL files in my java web app with the following code:

InputStream is = Dummy.class.getResourceAsStream("content.owl");

I created Dummy.class in the same package as content.owl is to get access to thi开发者_StackOverflow社区s file.

Is there a (refactor-safe) way to load content.owl directly without the need of a dummy class?


I think you should be able to get that resource from any class by giving relative path of it according to location of output folder where your compiled files are put.

For example initially the resource file in proj/src/a/b/content.owl package and the class I access this resource is in package proj/src/a/b/c/d/MyClass.java. After building the project my executables go under bin folder and the class I access the resource goes to proj/bin/a/b/c/d/MyClass.class directory and resource goes into proj/bin/a/b/content.owl.

And as bin folder is specified as the output folder in classpath of my project, I can access to resource with the code:

InputStream is = MyClass.class.getResourceAsStream("/a/b/content.owl");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜