Switch to full style
General Java code examples
Post a reply

Java properties utility

Sat Nov 27, 2010 10:17 pm

This class show you how to load properties from class path or from file system.
Code:

import java
.util.Properties;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.net.URL;

public class 
PropertiesUtility {

    private 
PropertiesUtility() {
    }

    
/**
     * Get the property from the class-path .
     * @param propsName
     *    The property name to which we get the value from .
     * @return Properties
     *     The properties loaded .
     * @throws Exception
     *    Any exception thrown , you will need to catch it .
     */
    
public static Properties load(String propsNamethrows Exception {
        
Properties props = new Properties();
        
URL url ClassLoader.getSystemResource(propsName);
        
props.load(url.openStream());
        return 
props;
    }

    
/**
     * Load all the  Properties File
     * @param propsFile
     *    PropsFile which
     * @return Properties
     *    return the properties loaded from the file .
     * @throws IOException
     *  Any IOException thrown , you will need to catch it.
     */
    
public static Properties load(File propsFilethrows IOException {
        
Properties props = new Properties();
        
FileInputStream fis = new FileInputStream(propsFile);
        
props.load(fis);
        
fis.close();
        return 
props;
    }
}


 




Post a reply
  Related Posts  to : Java properties utility
 simple code to read properties in java     -  
 links CSS properties     -  
 Change the properties of div tag     -  
 Change CSS Properties from JQuery     -  
 Class static properties     -  
 Changing the color and properties of the header tag     -  
 Define boolean Class properties     -  
 demonstrate how to add lighting and material properties     -  
 JFrame properties for an Applet to be embedded in website?     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  

Topic Tags

Java Files and I/O