|
|
Re: Open file in working directory
|
Posted: May 14, 2007 11:30 PM
|
|
> I created a JSP in a /webapps/TEST directory of my Tomcat > installation and want to simply open/read a file that also > exists in this same directory. > > My apps works correctly if I give the filename an absolute > path: > > i.e. > > File configFile = new File("C:\\TEST\\test.cfg"); > > however, I want to avoid using a hard-coded absolute path > and just open the file from where my jsp also resides. > I'm sure this is doable pretty easily, but can't find a > a straight answer. > > Any help would be appreciated.
I am not getting exactly whats ur working dir. What u can do is,
1. Get the working directory. 2. Instead of hard-coding the entire path, use the relative path from there.
Lets say ur JSP is in c:\tomcat\webapps\test And when u try to read the working directory, it gives c:\tomcat. Then u can replace ur foll line: <b>File configFile = new File("C:\\TEST\\test.cfg");</b> with <b>File configFile = new File("test\\test.cfg");</b>
Hope this works for u.
Regards, Rajeev
|
|