Not able to create new file using FileOutputStream in Servlet

kilometrvodi

New Member
I am using below code for creating a XML file using Stax Parser in one of my project. I used this code before in normal java application and its running fine there. But when I implement this for the Servlet i don't know why its not running. I am not getting any error in this but the XML file is not generated.\[code\]private static ServletContext sc; public void init(ServletConfig config) throws ServletException { // TODO Auto-generated method stub sc = config.getServletContext(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = sc.getRealPath("/WEB-INF/xml"); System.out.println("Path ==>" + path); XMLOutputFactory factory = XMLOutputFactory.newInstance(); File f = new File(path+"/atms.xml"); XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream(f)); //Some more code writer.writeStartDocument(); writer.writeStartElement("xxx"); writer.writeStartElement("yyy"); writer.writeStartElement("id"); writer.writeCharacters("1"); writer.writeStartElement("name"); writer.writeCharacters("Table"); writer.writeStartElement("price"); writer.writeCharacters("110"); writer.writeEndElement(); writer.close();}\[/code\]
 
Back
Top