File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes reading files from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "reading files from servlet" Watch "reading files from servlet" New topic

reading files from servlet

kiran nori

Joined: May 28, 2001
Posts: 12
hi all,
I'm using tomcat. I have a function which reads a XMl file and sets the required variables.I need to provide the file name to the file as a string. when I try to give a relative path tomcat gives me the following error
I do this :
File objXML = new File("Metadata.xml");
System.out.println("\nThe absolutepath of the file is : "+objXML.getAbsolutePath());
And it returns this:
The absolutepath of the file is : D:\TomCat\bin\DATMetadata.xml
but the file is existing in some other How to set a directory from where it reads the files.
Kiran Mohan Nori
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

what about using the dual argument constructor for File?

File f = new File(path, filename);
kiran nori

Joined: May 28, 2001
Posts: 12
I can't hardcode the path as my program can be deployed in any directory.
subject: reading files from servlet
Similar Threads
Binary Files
I want to get a file from a folder on the server using RMI
File q from mock exam -- ??? -confused!
Searchable plugin with Tomcat
BulkUpload from a remote computer to the server