Hi Jonathan,
 
   I have only done this as a stan alone app but I think it should work for you as long as the file you want to read is on the classpath.
 
Here is the code:
 
import java.io.*;
 public class Cat  {
   public static void main (String args[]) {
     String thisLine;
     Class cl = Cat.class; 
        try {
           BufferedReader myInput = new BufferedReader
               (new InputStreamReader( cl.getResourceAsStream("test.xml") ));
 
           while ((thisLine = myInput.readLine()) != null) { 
              System.out.println(thisLine);
           }
        }
        catch (Exception e) {
          e.printStackTrace();
        }
  }
}
 
--Abraham
-----Original Message-----
From: Jonathan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 11:05 AM
To: [EMAIL PROTECTED]
Subject: Opening a file

Hello All.
If I want to read in a file from a class which is NOT A SERVLET, such as Action, how do I refer to it.  Let me clarify this.  If it was a servlet I could have got the context, and from there a relative path.  BUT, from within a class there IS NO CONTEXT.  For example, I am running weblogic.  When I search for a file without specifying the path it searches from the "weblogic" directory, the place where I ran the startup script.  I only know this to be true because after 1000 painfull attempts it finally loaded my xml file from that directory when I placed it there.  How do you refer to a file from within a non servlet class?  Here is my code to refer to the file I want to open:
 
File mappingfile = new File("character_mappings.xml");

Reply via email to