How do I find a text file I want to load?

Discussions

General J2EE: How do I find a text file I want to load?

  1. How do I find a text file I want to load? (1 messages)

    Hello All.
    If I want to read in a file from a class which is NOT A SERVLET, 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");

    Do I have to use an absolute reference to the System property "user.dir" ?
  2. Generally, you can specify files and directories in configuration files, which are kept in a standard location and are accessible based on system.home or another weblogic property. You can store the location of the file you want to open in your configuration file.

    Does this help?

    Steve