I’m creating a dynamic web project in Eclipse where I frequently have write and read to and from an XML file. The file is in my project workspace in a folder called xml. I was wondering if Java provided some way to access the file without hard coding the file path. I’ve been looking around for a while for a solution but I haven’t really founding anything that’s really clear. Thanks!
Share
You can get the proper path using the following from your Servlet:
NOTE:
getRealPathmay returnnullif the file is inside a WAR file. In that case, if your file is inWEB_INF/classes, then you could useServletContext.getResourceAsStream("/config.xml").See this link: