Thursday, February 3, 2011

Using JSF : To Track XML file location which is under the Web application

 HI

There is an web application, where my xml file is under the WEB Content folder.

/JavaSource
/WEB Content
       /xml/test.xml
/WEB-INF


we can get the location of .xml file using the below suggested code :

ServletContext serCtx = (ServletContext) FacesContext
                    .getCurrentInstance().getExternalContext().getContext();

String filepath = serCtx.getRealPath("/xml/test.xml");


We can get the path of the xml file, where it stored while running the project and we can modify xml and save the file in the same location by using the below code

new XMLOutputter(Format.getPrettyFormat()).output(org.jdom.Document doc,
                    new FileWriter(filepath));

No comments :

Post a Comment