Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open File Question?

 
Jackson Yen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
 
Ct Arrington
Author
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic