Using property files - II
16 May 2008This 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.
Related Posts:
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