如何在Java中获取相对路径

时间:2013-12-13 17:17:48

标签: java nullpointerexception relative-path filereader absolute-path

我试图在我的Java代码中包含文件testrules.drl,但它一直给我一个NullPointerException。我是否正确宣布了相对路径?我用绝对路径尝试了它,但我仍然得到同样的错误......

private static String DRL_FILE = "/src/main/resources/rules/testrules.drl";
...
Reader reader = new InputStreamReader(Main.class.getResourceAsStream(DRL_FILE)); //this gives a NullPointeException

下面是图片:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用此

new InputStreamReader("src/main/resources/rules/testrules.drl");