I have been reading the same questioned that were asked here and on Quora, however, I still don`t understand why I cannot access the file that is located in the 'src/main/resources' folder. Everything works when I specify relative path manually "src/main/resources/config/serverConf.xml"
Project structure:
src/main/java/"project related folders"
src/main/resources/config/serverConf.xml
And the main class:
public class Main{
public Main(){
File file = new File(this.getClass().getResource("config/serverConf.xml").getPath());
if(file.exists())
System.out.println("Yes");
else
System.out.println("No");
}
public static void main(String[] args){
Main main = new Main();
}
}
Filecan be represented as anURL, not allURLs can be represented as aFile. Try printing the URL returned from.getResource(and see if it contains a!. If so, that's one of the times. My question for you is why does this program need aFileas opposed to anURLor (otherwise) just access to the resource?@is important) to notify the person of a new comment.