Re: Find current directory of java program running

Milt Epstein <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <[email protected]>
On Fri, 20 Jun 2003, Xu, John wrote:

> Milt,
> Thanks for your response.
> The purpose to do this is to find the current directory to open a
> property file which is located in a directory that this program is
> running.

You may want to do a search on this (either on the web, newsgroups, or
this list's archives), because this is a pretty common thing to do.
"property file" or "configuration file" would be good search terms.

But I think you want to use getResource(), or getResourceAsStream() --
that abstracts the file to a "resource", and you don't have to worry
about filesystem directories and paths.  Jason Hunter discusses it in
the following article (it's a chapter from the book Java Enterprise
Best Practices):

http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index1.html

Also, remember, "this program" is Tomcat, so the "directory that this
program is running" is where Tomcat was started from.  And that's
probably not what you want.


> -----Original Message-----
> From: Milt Epstein [mailto:[email protected]]
> Sent: Friday, June 20, 2003 5:00 PM
> To: [email protected]
> Subject: Re: Find current directory of java program running
>
>
> On Fri, 20 Jun 2003, Xu, John wrote:
>
> > Hi,
> > For a jsp page or servlet running within Tomcat, what is the good
> > way to find the directory that it is running?  Can we use
> > System.getProperty("user.dir")?
>
> For the best answer, you should describe why you want to do this
> and/or what are you trying to do.  Then we can tell you the
> best/cleanest way to do it.
>
> Milt Epstein
> Research Programmer
> Integration and Software Engineering (ISE)
> Campus Information Technologies and Educational Services (CITES)
> University of Illinois at Urbana-Champaign (UIUC)
> [email protected]
>
> ___________________________________________________________________________
> To unsubscribe, send email to [email protected] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [email protected] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>

Milt Epstein
Research Programmer
Integration and Software Engineering (ISE)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
[email protected]

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.