tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: how can I make my Java code write to a file using relative paths
Date Tue, 11 Feb 2003 07:08:21 GMT
To follow up on Tim's suggestion:

use:
  out = new
FileOutputStream(application.getRealPath("WEB-INF\\classes\\response.txt",
true);

(Here, 'application' has it's JSP meaning as the ServletContext, for a
GenericServlet, replace it by getServletContext()).

Of course, you are SOL if you doing this is you are using unpacked-war
files. In this case the best that you can do is:

  out = new FileOutputStream(new
File(application.getAttribute("javax.servlet.context.tempdir"),"response.txt
"),true);


"Tim Funk" <funkman@joedog.org> wrote in message
news:3E48296F.7030507@joedog.org...
> Don't rely on relative paths. At any point in time - someone can change
> the current working directory and throw any preconceived notions way off.
>
> Use absolute paths. Get the base path directory by configuring it in
> web.xml or server.xml.
>
> -Tim
>
> runu rathi wrote:
> > Hi all,
> > I am using the following statement in my .java file
> >
> > out = new FileOutputStream("responses.txt", true);
> >
> > I assumed that it should write in a file in the same
> > directory as the .java file in web-inf/classes
> >
> > but instead it writes in C:\WINNT\system32
> >
> > How can I get it to write at a particular place using
> > relative paths.
> >
> > I shall appreciate any help.
> > Thanks,
> > Runu




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message