May 19, 2007

java: Using ClassLoader to read a properties file in classes

Properties properties = null;
  String CONFIGURETIONFILE = "com/travelsky/titi/common/GlobalParameters.properties";
  if (properties == null) {
   try {
    properties = new Properties();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream inputStream = null;
    if (cl != null) {
     inputStream = cl.getResourceAsStream(CONFIGURETION
FILE);
    }
    if (inputStream != null) {
     properties.load(inputStream);
     inputStream.close();
     //set database parameters
     DbUtils.databaseType = Integer.parseInt(properties.getProperty("database.databaseType"));
     DbUtils.driverClassName = properties.getProperty("database.driverClassName");
     DbUtils.url = properties.getProperty("database.url");
     DbUtils.username = properties.getProperty("database.username");
     DbUtils.password = properties.getProperty("database.password");
     //set uploadFileDir
     GlobalParameters.uploadFileDir=properties.getProperty("uploadFileDir");
     //set userId and password
     GlobalParameters.userId=properties.getProperty("userid");
     GlobalParameters.password=properties.getProperty("password");
     
     System.out.println("Getting global parameters successfully!");
    }
    
   } catch (Exception e) {
    e.printStackTrace();
    System.out.println("ERRORS:error on getting global parameters!");
   }

a funny scrawl

This scrawl was found on the road behind Fortune Plaza.

It must be left by an angry street hawker.

being a driver(I)

being a driver-I

continued…