Java Properties Load from File loadProperties(String propsFile)

Here you can find the source of loadProperties(String propsFile)

Description

Creates a new Properties object from the properties file located at the argument location

License

Open Source License

Parameter

Parameter Description
propsFile location of the properties file

Return

New properties object created from the file located at the argument location

Declaration

public static Properties loadProperties(String propsFile) 

Method Source Code


//package com.java2s;
/*/*from  w  w  w. j a  v  a 2s  .c om*/
 *  Copyright 2008 The MITRE Corporation (http://www.mitre.org/). All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.util.Properties;

public class Main {
    /**
     *  Creates a new Properties object from the properties file located at the
     *  argument location
     *
     *@param  propsFile  location of the properties file
     *@return            New properties object created from the file located at
     *      the argument location
     */
    public static Properties loadProperties(String propsFile) {
        Properties ret = new Properties();
        try {
            File test = new File(propsFile);
            if (!test.exists()) {
                RuntimeException re = new RuntimeException("Could not find the properties file: " + propsFile);
                throw re;
            }
            InputStream in = new FileInputStream(propsFile);
            ret.load(in);
        } catch (IOException e) {
            RuntimeException re = new RuntimeException("Could not find the properties file: " + propsFile, e);
            throw re;
        }
        return ret;
    }
}

Related

  1. loadProperties(String path, Properties defaults)
  2. loadProperties(String propertiesFile)
  3. loadProperties(String propertiesFile)
  4. loadProperties(String propertyFile)
  5. loadProperties(String propertyPath)
  6. loadProperties(String sFile)
  7. loadPropertiesFile(File file, boolean critical)
  8. loadPropertiesFile(final File file)
  9. loadPropertiesFile(String fileName)