简体   繁体   English

如何在Java中获得相对路径

[英]How to get relative path in Java

I am trying to include the file testrules.drl in my Java code but it keeps giving me a NullPointerException. 我试图在我的Java代码中包含文件testrules.drl,但它一直给我NullPointerException。 Am I declaring the relative path correctly? 我是否正确声明了相对路径? I tried it with the absolute path but I still get the same error.... 我用绝对路径进行了尝试,但仍然遇到相同的错误...。

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

Below is the image: 下面是图像:

在此处输入图片说明

试试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM