es.prodevelop.pui9.utils.PuiPropertiesManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es.prodevelop.pui9.utils Show documentation
Show all versions of es.prodevelop.pui9.utils Show documentation
Multiple utilities for PUI9 (Gson, CSV, Exceptions...)
The newest version!
package es.prodevelop.pui9.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import es.prodevelop.pui9.classpath.PuiClassLoaderUtils;
/**
* A utility class to load properties files from its file name
*
* @author Marc Gil - [email protected]
*/
public class PuiPropertiesManager {
private PuiPropertiesManager() {
}
/**
* Tries to load the properties file with the given name. File name should
* contain the whole path from the root of the project
*
* @param filename The filename to be loaded
* @return The Properties object
* @throws IOException Exception if the file doesn't exist
*/
public static Properties loadPropertiesFile(String filename) throws IOException {
Properties props = new Properties();
InputStream is = PuiClassLoaderUtils.getClassLoader().getResourceAsStream(filename);
if (is != null) {
props.load(is);
} else {
File file = new File(filename);
if (file.exists()) {
try (InputStream is2 = new FileInputStream(file)) {
props.load(is2);
}
}
}
return props;
}
}