Well, you can access it in a portable way but note that you cannot count of File IO in servlets. If the webapp is served from a .war file then File IO will be impossible. Not sure if you can updated it in other ways. I suppose there are ways.
Here is how you load it:
InputStream propStream = getServletContext().getResourceAsStream("/WEB-INF/conf/config.properties");
Here is how to access your WEB-INF directory if the app is served off the filesystem. Note that this will return null if the app is served from a .war file:
String webinfPath = getServletContext().getRealPath("/WEB-INF/");
Using this, you can create a File object that points to your config.properties file and do any File IO you want. Again, there are risks involved, so be careful to make sure the app is served off the filesystem.
Jake
At 05:37 PM 11/18/2002 -0800, you wrote:
Help! I need configure my log4j to put log file under WEB-INF\logs(or maybe docroot\logs; and I want put my editable config properties into WEB-INF\conf. I know how to load a property file under WEB-INF. But I need update that file in program as well. So how can I: 1 Config log4j? 2 How do load and write the property file under WEB-INF?Thanks David Cao -- Innovation by Critical Thinking -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 06, 2002 6:56 AM To: Tomcat Users List Subject: Re: Location of application-specific properties files You must load your properties through some Classloader that is able to locate your properties file. For example you can use the class PropertyResourceBundle for a real properties file or if you want to access some own file format, just call the Thread.getCurrentThread ().getContextClassLoader().getResourceAsStream(...) function. Then the WEB-INF/classes folder or some of your application specific .jar files in WEB-INF/lib (if any) is the right place for it (and as far as i know, it is the only standard way, which assures you to find a specific file on every standard J2EE server). Hope that helps, Jens Stutte "Robert Baker" <robertbaker@ch To: "Tomcat Users List" arter.net> <[EMAIL PROTECTED]> cc: 04/08/2002 Subject: Location of application-specific properties 21.05 files Please respond to "Tomcat Users List" I am using Tomcat 4.0.3 under WinXP Pro, and I am trying to get my application to "find" an application-specific properties file. I am having problems trying to determine which directory to put this file in. Here is the Java code I am using for this class: //----------- import java.util.Properties; import java.io.FileInputStream; public class ForumProperties extends Properties { private static final String separator = System.getProperty("file.separator", "."); private static final String homeDirectory = System.getProperty("user.home","."); private static final String DEFAULT_FILENAME = "forum.properties"; private static ForumProperties globalProps; private ForumProperties() { } private ForumProperties(String fileName) throws Exception { this(); load(new FileInputStream(fileName)); } public static ForumProperties getInstance() throws Exception { try { if (globalProps == null) globalProps = new ForumProperties(DEFAULT_FILENAME); } catch (Exception ex) { ex.printStackTrace(System.out); throw new Exception("Error loading properties file"); } return globalProps; } } //----------- I have put the properties file in just about every directory I can think of to try and find out where it's supposed to be, but I can't get it to work. I can put the file into the "user.home" System property (which turns out to be C:\Documents and Settings\Administrator) and have it pick it up, but I would prefer to put the file into the directory tree of the application. Is there an attribute or something in the server.xml or web.xml file I am forgetting to set? Can anyone help? Thanks, Bob -- To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED]> For additional commands, e-mail: < mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
