• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading files from servlet

 
kiran nori
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
rgds
Kiran Mohan Nori
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about using the dual argument constructor for File?

File f = new File(path, filename);
 
kiran nori
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't hardcode the path as my program can be deployed in any directory.
rgds
Kiran
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic