tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeffrey Winter" <>
Subject Re: getCanonicalFile()
Date Fri, 10 Jan 2003 22:57:01 GMT

> If you need to reference files in some arbitrary directory someplace, you
> should pass the pathname of that directory to your servlet as an init
> parameter, and then use that path to construct an absolute path to the
> file you want.

In my particular case the files I'm attempting to open are ones that are
being created and read by the application itself and are not deployed as
part of the web application.

I actually am passing in a directory name as a <context-param> though
this name has not path in it, it's just the flat name of the directory,
e.g., "somedir".  This value is read in in the init() method, so when
I create the file path I do essentially:

    File file = new File(directory + File.separator + "filename");

Granted, the absolute directory is relative to the context that Tomcat
itself is running in, but that is perfectly fine in my case (I would

My real issue is that I don't understand why

    InputStream stream = new FileInputStream(file);

would be any different from

    InputStream stream = new FileInputStream(file.getCanonicalFile());


    file.getAbsolutePath();   and

return the exactly the same string.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message