Re: open a file outside JSP
nashaccount wrote:
Thanks for your reply Lew.
My file is located at: c:\reports. When in production (UNIX), my file
will be located at: /reports/
How are you guaranteeing this?
The regular File (and FileXxxStream, File{Reader,Writer}) classes work with
full paths. The methods I mentioned are for finding resources relative to
your application's location.
Relative locations are *much* easier to manage and guarantee, and are much
more portable. (Likely portability is not a requirement for you, reading
between the lines. But it is generally a bad idea to make non-portable Web apps.)
So as you've mentioned before I can't hardcore though.
Assuming you mean "hardcode", why not? I mean, I know I said you shouldn't,
but I never said you can't.
That said, go the deployment descriptor or properties file route - it provides
portability while still allowing full-path references.
Regarding the links that you've just sent to me, isn't ClassLoader
only useful to find out classes?
No. Didn't you read the Javadocs that I linked for you? If not, do that now.
For your needs, java.io.FileXxx classes may be better. Check out their
Javadocs and see if they suit. The combination of a configuration file
specifying, say, "C:/reports/myreport.log" and code using FileWriter is pretty
powerful.
--
Lew