I'm trying to access a file test.gif
located at (src/main/resources/test.gif
in Eclipse),from my program using the absolute path using the ClassLoader
, in the following manner
String absPath=this.getClass().getResource("/test.gif").toString();
System.out.print(Path);// prints the absolute path /Users/Abby/Project/SubFolder/ProjectName/target/classes/test.gif - the file exists at the location.
String relPath= "src/main/resources/test.gif";
However, accessing absPath
causes a FileNotFoundException in my program whereas using relPath
does not.
What exactly am I doing wrong? And how do I correctly access the file using the absolute path (via ClassLoader)