Java Properties Load from File loadPropertiesFile(final File file)

Here you can find the source of loadPropertiesFile(final File file)

Description

Loads the given file as a Properties file.

License

Open Source License

Parameter

Parameter Description
file the file to load the propertied from

Return

properties loaded

Declaration

public static Properties loadPropertiesFile(final File file) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   w w  w.jav  a  2  s.c  o m*/
 * ====================
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Common Development
 * and Distribution License("CDDL") (the "License").  You may not use this file
 * except in compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://opensource.org/licenses/cddl1.php
 * See the License for the specific language governing permissions and limitations
 * under the License.
 *
 * When distributing the Covered Code, include this CDDL Header Notice in each file
 * and include the License file at http://opensource.org/licenses/cddl1.php.
 * If applicable, add the following below this CDDL Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * ====================
 * Portions Copyrighted 2013 ConnId
 * Portions Copyrighted 2015 ForgeRock AS.
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

public class Main {
    /**
     * Loads the given file as a Properties file.
     *
     * @param file
     *            the file to load the propertied from
     * @return properties loaded
     */
    public static Properties loadPropertiesFile(final File file) throws IOException {
        FileInputStream in = new FileInputStream(file);
        try {
            final Properties rv = new Properties();
            rv.load(in);
            return rv;
        } finally {
            in.close();
        }
    }

    /**
     * Attempt to load file based on a string base filename.
     *
     * @param string
     *            represents the file.
     * @return a loaded properties file.
     * @throws IOException
     *             if there is an issue.
     */
    public static Properties loadPropertiesFile(final String string) throws IOException {
        return loadPropertiesFile(new File(string));
    }
}

Related

  1. loadProperties(String propertyFile)
  2. loadProperties(String propertyPath)
  3. loadProperties(String propsFile)
  4. loadProperties(String sFile)
  5. loadPropertiesFile(File file, boolean critical)
  6. loadPropertiesFile(String fileName)
  7. loadPropertiesFile(String fileName)
  8. loadPropertiesFile(String filePath)
  9. loadPropertiesFile(String filePath)