Using *.properties files in your servlet or webapp

January 22nd, 2010 by Bruce Dou Views:183
  1. import java.util.Properties;
  2.  
  3. ...
  4.  static String profilepath="webapps/ROOT/WEB-INF/server.properties";
  5.      private static Properties props = new Properties();
  6.  
  7.         static {
  8.              try {
  9.                 props.load(new FileInputStream(profilepath));
  10.             } catch (FileNotFoundException e) {
  11.                 e.printStackTrace();
  12.             } catch (IOException e) {       
  13.                 e.printStackTrace();
  14.             }
  15.         }
  16.           
  17.         public static String getKeyValue(String key) {
  18.             return props.getProperty(key);
  19.         }           
  20.      //the directory that is used to store lucene index
  21.   public final String indexDir = getKeyValue("INDEX_ROOT");
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • 豆瓣
  • DZone
  • LinkedIn
  • MySpace
  • Reddit
  • RSS

Also see:

Tags: ,

Leave a Reply