Hi,

excuse me, you're right in one aspect. I realized it later that 
I didn't read the whole question. I just thought: OH AGAIN. But
this doesn't make the answer wrong.

If you're in a servlet, no matter where, you can get the 
ServletContext by getServletContext(). From it you can have for
instance getResourceAsStream("/WEB-INF/file.properties"). If 
this doesn't work you might have done something wrong, maybe 
with the slashes or so?

If you're not in a servlet, make sure you pass a ServletContext
from a servlet to where you want to have it.

FileIO can be used, but it's not compatible with the spec. The
servlet spec says you are not guarantied to have FileIO other
than the temp directory and temp files. But also this has been
said many times.

However, if you know there is a file system, you can use normal
File IO. What you need is the right path. You could pass it as 
an init param in web.xml. From the servlet's init() you can get 
the param with getInitParameter("nameOfParam").

What do you mean by starting a standalone application? 


Andreas



On 19 Dec 2002 at 9:43, aps olute wrote:

>   May I kindly suggest you read the whole posting before
>   suggesting your
> solution.  You have not taken the time to read through it and
> making suggestions without reading the problem.  I did mention
> I tried getResourceAsStream() and had partial success.  The
> issue here is doing it from init() versus doGet() and btw why
> dont you address the question of WHY cant the FILE IO be used?
> what is the underlying reason. 
> 
> TIA
> 
> --- Andreas Probst <[EMAIL PROTECTED]> wrote:
> > Hi,
> > 
> > this question has been answered many times. Look for
> > "properties files" in the archive.
> > 
> > Hint: Use servletContext.getResourceAsStream();
> > 
> > 
> > On 19 Dec 2002 at 9:20, aps olute wrote:
> > 
> > > 
> > > 
> > >  Greetings,
> > >        I have been trying to do the following using Tomcat
> > >        4.1.12:
> > > 
> > > 1)  Attempt to have a servlet read a properties or any text
> > > file.
> > >  Reading the file from the doGet() method by:
> > > 
> > > BufferedReader br = null; 
> > > br = new BufferedReader(new FileReader(file));  //file is
> > > "test.properties"
> > > 
> > > Result: Varying success, because I dont quite comprehend
> > > the Tomcat "startup" directory.  Discovered that there is
> > > dependency on from where Tomcat was started. For example,
> > > if started Tomcat by ./bin/starup.sh from tomcat_home/bin/,
> > > I must have the file the servlet reads located at
> > > tomcat_cat/bin/.  If I started Tomcat from
> > > tomcat_home/webapps/  by  ../bin/startup.sh, I must have
> > > the properties file located at tomcat_home/webapps/ or else
> > > the servlet will not find this.
> > > 
> > > 2)  Atempt to have a servlet read a properties or any text
> > > file. Reading the file from the init() method by:
> > > 
> > > BufferedReader br = null; 
> > > br = new BufferedReader(new FileReader(file));
> > > 
> > > Result: Starting Tomcat from tomcat_home/bin/ by
> > > ./bin/startup.sh, failure to get Tomcat even to start, the
> > > log shows it only goes as far as Apache Tomcat/4.1.12 and
> > > stops. Starting Tomcat from tomcat_home/webapps/ by
> > > ../bin/startup.sh Tomcat starts, some other context are
> > > running, but the servlet reading this properties file on
> > > this specific context fails to find the properties file. 
> > > Is using File IO bad in the init() method? I want to do
> > > this to initialize a standalone application.
> > > 
> > > I surmized I cant read a properties file from init() method
> > > using File class. I did try as one suggested about using
> > > getResourceAsStream() with partial success.
> > > 
> > > 3) Can a stand alone application be started at all from a
> > > servlet?  I cant seem to get this to work, either from the
> > > init() or doGet() method. I can not launch an application
> > > why from a servlet, why?
> > > 
> > > Any help on #3 please?
> > > 
> > 
>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to