Using property files - II

16 May 2008

This post is in continuation of ‘Using property files - I’. Do read that before this one.

The Properties class stores the set of pairs in a hashtable, so there is no guarantee for order. Another interesting example of loading property file is given below:

public class LoadProps {
 
   public static void main(String args[]) throws Exception{
      h.doit();
      h.doitagain();
      }
   public void doit() throws Exception{
      // properties in the classpath
      java.util.Properties props = new java.util.Properties();
      java.net.URL url = ClassLoader.getSystemResource("myprops.props");
      props.load(url.openStream());
      System.out.println(props);
     }
   public void doitagain() throws Exception{
      // properties in the startup directory
      java.util.Properties props = new java.util.Properties();
      String path = getClass().getProtectionDomain().getCodeSource().
                    getLocation().toString().substring(6);
      java.io.FileInputStream fis = new java.io.FileInputStream
         (new java.io.File( path + "\\myprops.props"));
      props.load(fis);
      System.out.println(props);
     }
}

Hope this helps.

del.icio.us:Using property files - II  digg:Using property files - II  spurl:Using property files - II  wists:Using property files - II  simpy:Using property files - II  newsvine:Using property files - II  blinklist:Using property files - II  furl:Using property files - II  reddit:Using property files - II  fark:Using property files - II  blogmarks:Using property files - II  Y!:Using property files - II  smarking:Using property files - II  magnolia:Using property files - II  segnalo:Using property files - II  gifttagging:Using property files - II

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Using property files - II

Leave a Reply