Had a similar problem. This code seems to work in a servlet (more comment
after):

------------------
        PrintWriter out = null;
        ServletContext servletContext = getServletContext();

        try
        {
            out = response.getWriter();
        }
        catch ( IOException ioe)
        {
            return;
        }

        InputStream inStream = servletContext.getResourceAsStream( "/blotto"
);
        BufferedReader in
           = new BufferedReader(new InputStreamReader( inStream ) );

        try
        {
            for(String line = ""; (line = in.readLine()) != null; )
            {
                out.print(line);
                out.flush();
            }
        }
        catch ( IOException ioe ) {}
-------------------

 The text file 'blotto' is in directory <context>. That is, the name of your
app, the directory below webapps but above WEB-INF.




> -----Original Message-----
> From: Xiao, Wei [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 26, 2002 12:55 PM
> To: Tomcat Users List
> Subject: RE: Properties files.
>
>
> I just removed "/" in front of the properties files. I even checked
> index$jsp.java file. But I am still getting the same exception.
>
> Wei
>
> -----Original Message-----
> From: David Burns [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 26, 2002 3:49 PM
> To: Tomcat Users List
> Subject: Re: Properties files.
>
>
> Are you sure you want the "/" in the name?
>
> On Tuesday 26 March 2002 03:43 pm, you wrote:
> > I put abc.properties in .../WEB-INF/classes and have the
> following codes,
> > it gave me NullPointerException.
> >
> > java.util.Properties props = new java.util.Properties();
> > java.io.InputStream is =
> > props.getClass().getResourceAsStream("/abc.properties");
> > props.load(is);
> >
> > java.lang.NullPointerException
> >     at java.io.InputStreamReader.(InputStreamReader.java:85)
> >     at java.io.InputStreamReader.(InputStreamReader.java:74)
> >     at java.util.Properties.load(Properties.java:176)
> >     at org.apache.jsp.index$jsp._jspService(index$jsp.java:66)
> >
> > Thank you.
> >
> > Wei
> >
> > -----Original Message-----
> > From: David Burns [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, March 26, 2002 3:06 PM
> > To: Tomcat Users List
> > Subject: Re: Properties files.
> >
> >
> > I load application property files off the classpath and was
> able to load
> > property files from mywebapp/WEB-INF/classes directory.
> Had a little
> > trouble
> > with the log4j.properties, had to place that file in
> common/classes (may
> > have
> > to do with where log4j.jar is located).
> >
> > Hope this helps.
> >
> >     -- David.
> >
> > On Tuesday 26 March 2002 02:56 pm, you wrote:
> > > Hi all,
> > >
> > > I was trying to migrating an existing application to
> Tomcat 4.0. We used
> > > a lot of properties files and just specified the
> directory in classpath,
> >
> > then
> >
> > > we can call
> > > load("/abc.properties"). Where should I put properties files
> >
> > (*.properties)
> >
> > > in tomcat? How should I call to load it?
> > >
> > > Thanks a lot.
> > >
> > > Wei
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to