File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes portability issues with file i/o Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "portability issues with file i/o" Watch "portability issues with file i/o" New topic

portability issues with file i/o

Micah Wedemeyer
Ranch Hand

Joined: Jun 11, 2001
Posts: 68
Is there any sort of specifics as to where a servlet's "home" directory is? When my servlet writes a file, it seems almost arbitrary where it goes. On Tomcat it goes into the /bin directory while on JRun 2.3 it goes into the enclosing web server main directory. This is causing problems for me on JRun due to read/write security restrictions.
I suppose it would be possible to give an absolute path, but this would destroy portability across even a single machine, let alone multiple Servlet Engines. Does anyone have any suggestions?
Micah Wedemeyer
Ranch Hand

Joined: Jun 11, 2001
Posts: 68
Never mind. After some concerted searching on the rest of the board I found the getServletContext().getRealPath() stuff.
Thanks to anyone who was going to help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

Hmmm. I think you may have solved quite a few people's problems here. However, this isn't literally the "home" of the servlet - it's the absolute pathname for a given context (virtual path), so it's not for everyone. And they did note it breaks down if the item in question's inside a "WAR".
Still, it's good to know...

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: portability issues with file i/o
It's not a secret anymore!