I have my java file in
/src/main/java/Test.java
and I want to read a property file/XML file from
/src/main/resources/plugin.properties and/or
/src/main/resources/templates/basic_java.xml
When I try to read these files from Test.java (after deployment of course), it is not able to do so and giving the error
java.io.FileNotFoundException: /target/plugin.properties (No such file or directory) at java.io.FileInputStream.open0(Native Method)
Though I can find the plugin.properties and basic_java.xml under /target/classes folder, yet it cannot read these files.
I have tried multiple solutions including :
1. getClass().getResource("Test.java");
2. new File(".").getCanonicalPath() + "target//plugin.properties";
3. ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs()
4. ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getResourceAsStream("Test.java")
5. Thread.currentThread().getContextClassLoader().getSystemResources("Test.java");
6. new FileInputStream("src\\main\\resources\\plugin.properties");
7. new FileInputStream("resources\\plugin.properties");
8. new FileInputStream("src\\main\\resources\\plugin.properties");
9. new FileInputStream("\\plugin.properties");
10. new FileInputStream("\\classes\\plugin.properties");
but no luck.