This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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
Joined: Oct 04, 2002
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.
Author and all-around good cowpoke
Joined: Mar 22, 2000
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
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