load Properties from class path - Java java.util

Java examples for java.util:Properties File

Description

load Properties from class path

Demo Code

/*/*from ww  w  .  java 2 s .c  o  m*/
 * SK's Minecraft Launcher
 * Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
 * Please see LICENSE.txt for license information.
 */
//package com.java2s;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Main {


    public static Properties loadProperties(Class<?> clazz, String name)
            throws IOException {
        Properties prop = new Properties();
        InputStream in = null;
        try {
            in = clazz.getResourceAsStream(name);
            prop.load(in);
        } finally {
            closeQuietly(in);
        }
        return prop;
    }

    public static void closeQuietly(Closeable closeable) {
        try {
            if (closeable != null) {
                closeable.close();
            }
        } catch (IOException e) {
        }
    }
}

Related Tutorials