Total members 11893 |It is currently Tue Nov 05, 2024 4:35 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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;
    }
}


 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Java properties utility
 simple code to read properties in java     -  
 Change the properties of div tag     -  
 links CSS properties     -  
 Class static properties     -  
 Change CSS Properties from JQuery     -  
 demonstrate how to add lighting and material properties     -  
 Changing the color and properties of the header tag     -  
 Define boolean Class 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






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com