简体   繁体   中英

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. 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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