xmlaccessibilitynetbeans7.0

How do you use an XML as a database in Netbeans without absolute paths?


Due to work, I have to use XML files as a database. There are only two of them at the moment: products.xml and users.xml. Both XMLs won't be storing much information. We are using Netbeans 7.0 and Tomcat 7.0.11.

The problem is that when trying to access the files to read AND write, we have to use an absolute path: C:/../../../Project_Name/DATA/products.xml. However, we have to make it so that the XML files can be accessed with a relative path: /DATA/products.xml. Is there a way to do so?

I am aware that using a database would probably make things much easier, however that is not an option.

Thanks for any help.


Solution

  • You can put the files in your classpath and access them with Classloader.getResourceAsStream.