I am trying to generate a XML file and save it in /WEB-INF/pages/
.
Below is my code which uses a relative path:
File folder = new File("src/main/webapp/WEB-INF/pages/");
StreamResult result = new StreamResult(new File(folder, fileName));
It's working fine when running as an application on my local machine (C:UsersuserNameDesktopSourceMyProjectsrcmainwebappWEB-INFpagesmyFile.xml).
But when deploying and running on server machine, it throws the below exception:
javax.xml.transform.TransformerException:
java.io.FileNotFoundException
C:projecteclipse-jee-luna-R-win32-x86_64eclipsesrcmainwebappWEB INFpagesmyFile.xml
I tried getServletContext().getRealPath()
as well, but it's returning null
on my server. Can someone help?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…