Java Properties Load from File loadProperties(File file)

Here you can find the source of loadProperties(File file)

Description

Loads properties from a file if it exists.

License

LGPL

Parameter

Parameter Description
file The file

Exception

Parameter Description
IOException In case of a reading error

Return

The properties

Declaration

public static Properties loadProperties(File file) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  w w  w .j a  va 2  s. co m*/
 * Copyright 2009-2016 Three Crickets LLC.
 * <p>
 * The contents of this file are subject to the terms of the LGPL version 3.0:
 * http://www.gnu.org/copyleft/lesser.html
 * <p>
 * Alternatively, you can obtain a royalty free commercial license with less
 * limitations, transferable or non-transferable, directly from Three Crickets
 * at http://threecrickets.com/
 */

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

import java.io.IOException;

import java.util.Properties;

public class Main {
    /**
     * Loads properties from a file if it exists.
     * 
     * @param file
     *        The file
     * @return The properties
     * @throws IOException
     *         In case of a reading error
     */
    public static Properties loadProperties(File file) throws IOException {
        Properties properties = new Properties();
        try {
            FileInputStream in = new FileInputStream(file);
            try {
                properties.load(in);
            } finally {
                in.close();
            }
        } catch (FileNotFoundException x) {
            // This is allowed.
        }
        return properties;
    }
}

Related

  1. loadProperties(File f)
  2. loadProperties(File file)
  3. loadProperties(File file)
  4. loadProperties(File file)
  5. loadProperties(File file)
  6. loadProperties(File file)
  7. loadProperties(File file)
  8. loadProperties(File file)
  9. loadProperties(File file)