Here you can find the source of load(Class> cls)
Parameter | Description |
---|---|
cls | The class to load the properties for. |
Parameter | Description |
---|---|
IOException | if an I/O error occurs during loading. |
public static Properties load(Class<?> cls) throws IOException
//package com.java2s; /*/*from w w w . ja v a 2 s .c o m*/ * Copyright (c) 2016-2017 Holger de Carne and contributors, All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class Main { /** * Load a {@link Properties} object for a specific class. * <p> * This function assumes that the properties file is a resource named as the submitted class with the extension * .properties. * * @param cls The class to load the properties for. * @return The loaded properties. * @throws IOException if an I/O error occurs during loading. */ public static Properties load(Class<?> cls) throws IOException { Properties properties; try (InputStream stream = cls.getResourceAsStream(cls.getSimpleName() + ".properties")) { if (stream == null) { throw new FileNotFoundException("Resource not found for class: " + cls.getName()); } properties = new Properties(); properties.load(stream); } return properties; } }