I have built a dynamic web project MusicStore
in Eclipse, and I want to access an xml file located in WebContent/_res/Songs.xml
. The method I used to access it in a regular Java class[not a servlet]
is:
URL url = this.getClass().getClassLoader().getResource("/");
String filePath = url.getFile();
String webAppLoc=new File(filePath).getParentFile().getParent();
String resLoc=webAppLoc+"/_res/Songs.xml";
It seems to me that this is very cumbersome. Is there a better, more efficient way? thanks!
Here you can try this to access file