aspose file tools*
The moose likes XML and Related Technologies and the fly likes sax java.io.FileNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "sax java.io.FileNotFoundException" Watch "sax java.io.FileNotFoundException" New topic
Author

sax java.io.FileNotFoundException

Francois Bourgault
Ranch Hand

Joined: Oct 30, 2001
Posts: 67
Hi all,
I have a class "xml_to_java". It is supposed to print out all the elements of "java_exam.xml". It is invoked from a servlet "trans_xml_java". I have the xml file in "/WEB-INF/" and both classes are in "WEB-INF/classes" Somehow I get the above io error. The only place where the class finds the xml file is when the xml file is in "jakarta-tomcat/bin". I also copied the file in the root of my application, but it doesn't work. Any idea what I'm doing wrong?
Regards,
Francois.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
With tomcat the default file location is /bin directory, its not a good idea to place the work files under the bin directory - because not all servlet containers can read it.
My idea could be create a directory xmlfiles under web-inf and refer its location in web.xml file

<context-param>
<param-name>xmlfileloc</param-name>
<param-value>/web-inf/xmlfiles</param-value>
<description>Default xml file location</description>
</context-param>

Now in ur servlet try to get this parameters with the following code
String xmlfileloc = getServletContext().getInitParameter("xmlfileloc");


Spritle Software Blogs
Francois Bourgault
Ranch Hand

Joined: Oct 30, 2001
Posts: 67
Hi Balaji,
Sorry about the late reply. What you mention still doesn't work. Even if I hardcode the path, tomcat can't find the file. Here's my setup in tomcat:
<webapps>/<my_appl>/source code
<webapps>/<my_appl>/<WEB-INF>/<classes>/*.class
<webapps>/<my_appl>/<xmlfiles>a_xmlfile.xml
I use Tomcat 4.1.18 and I have the following code in xml_to_java.class
xml_nm = "\my_appl\xmlfiles\java_exam.xml";
XMLReader xr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
xr.setContentHandler( this );
xr.parse( new InputSource( new FileReader( xml_nm )) );
This won't work. The only xml file it reads is the one in the bin subdirectory.
What else am I missing in Tomcat setup?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sax java.io.FileNotFoundException