Java Properties Load from File loadPropertiesFromFile(String fullFileName)

Here you can find the source of loadPropertiesFromFile(String fullFileName)

Description

Load all properties from a file

License

LGPL

Parameter

Parameter Description
fullFileName full name of the file

Return

properties in the resource

Declaration

public static Properties loadPropertiesFromFile(String fullFileName)
        throws Exception 

Method Source Code

//package com.java2s;
/*/* ww  w .ja  v a2s  .c o  m*/
 *   This software is distributed under the terms of the FSF 
 *   Gnu Lesser General Public License (see lgpl.txt). 
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.util.Properties;

public class Main {
    /**
     * Load all properties from a file 
     * 
     * @param fullFileName full name of the file
     * @return properties in the resource
     */
    public static Properties loadPropertiesFromFile(String fullFileName)
            throws Exception {
        Properties props = new Properties();
        loadPropertiesFromFile(props, fullFileName);
        return props;
    }

    /**
     * Load all properties from a file 
     * 
     * @param props properties to load file
     * @param fullFileName full name of the file
     * @return properties in the resource
     */
    private static void loadPropertiesFromFile(Properties props,
            String fullFileName) throws Exception {
        InputStream is = null;
        try {
            // load all properties
            is = new FileInputStream(fullFileName);
            if (is != null) {
                props.load(is);
                is.close();
            }
        } catch (FileNotFoundException fnfe) {
            throw new Exception("File (" + fullFileName
                    + ") does not exist.");
        } catch (IOException ioe) {
            throw new Exception("Error reading file " + fullFileName + ".");
        } finally {
            try {
                if (is != null)
                    is.close();
            } catch (Exception ex) {
                is = null;
            }
        }
    }
}

Related

  1. loadPropertiesFromClasspath(String pfname)
  2. loadPropertiesFromFile(Class clazz, String filePath)
  3. loadPropertiesFromFile(JarFile jar)
  4. loadPropertiesFromFile(String configFile)
  5. loadPropertiesFromFile(String filePath)
  6. loadPropertiesFromFile(String pathname)
  7. loadPropertiesFromPath(String propsFilePath)
  8. loadPropertiesInClassPath(String propertiesFileName)
  9. loadProvidersConfiguration(Class base, String confPropertiesName)