• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Open File Question?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I would like to opening a file at a servlet. I just put the file name in the "FileInputStream" constructor and doesn't specify the path.
ex: FileInputStream in = new FileInputStream("test.cfg");
I use Tomcat as my AP server. Where should I put the config file when I want to open a file without specifying its path? Thanks.
ps. I use "ROOT" as my webapp location
Best Regards
Jackson
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should never open a file this way in a servlet. The reason being that it depends on the JVM's "current" directory. You have absolutely no control over the current directory from the servlet.
Much better to provide a complete path in the servlet initialization parameters. That gives you real flexibility to put test.cfg anywhere.
Bill
 
Jackson Yen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, William. But the servlet was written by Vendor. I am responsible for the deployment. As you mentioned in the above, where to put the file depends on JVM's current directory. If I put the config file to the same directory where the servlet was and then make a jar file, could the servelt find the config file? If not, the last way I can do is to ask Vendor to change the code.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I can't say as I think much of your vendor if they have not provided for some way to set the absolute path, or to use a location relative to the web application for your configuration file.
This is a very well known problem so they should have provided something.
Bill
 
Author
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jackson
Here is a crude way to figure it out:
Use FileOutputStream to write a test file from your test servlet. Then find the file within the filesystem.
If you can't modify the source code to make their servlet use a parameter to find the file, then I don't see any other way. Shame on the vendor!
Hope it helps
CT
 
Jackson Yen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thansk CI. I found where the file was. It is on my personal folder. The platform I use is Win2k. I should change "start in" locaton to the where I want ot put it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic