Java Properties Load from File loadProperties(File file)

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

Description

Loads properties from the specified file.

License

Open Source License

Parameter

Parameter Description
file file to load properties from.

Exception

Parameter Description
IOException if I/O exception occurs.

Return

properties. Never returns null.

Declaration

public static Properties loadProperties(File file) throws IOException 

Method Source Code


//package com.java2s;
/*//from w  w  w .j  a va2 s .com
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 *
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

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

import java.util.Properties;

public class Main {
    /**
     * Loads properties from the specified file.
     *
     * @param file file to load properties from.
     * @return properties. Never returns <code>null</code>.
     *
     * @throws IOException if I/O exception occurs.
     */
    public static Properties loadProperties(File file) throws IOException {
        FileInputStream input = null;
        try {
            input = new FileInputStream(file);
            Properties properties = new Properties();
            properties.load(input);
            return properties;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    throw new RuntimeException("Failed to close file:\n" + e);
                }
            }
        }
    }
}

Related

  1. loadProperties(File directory, String propertiesFileName)
  2. loadProperties(File f)
  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)