Primer commit Actividad 1.9
This commit is contained in:
@@ -1,29 +1,36 @@
|
||||
package org.palomafp.aadd.jx;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class GestorPropiedad {
|
||||
|
||||
|
||||
private static final String FICHERO_PROPIEDADES = "application.properties";
|
||||
|
||||
private static Properties propiedades = new Properties();
|
||||
|
||||
|
||||
static {
|
||||
|
||||
|
||||
Path ruta = Paths.get("config", "application.properties");
|
||||
|
||||
try (BufferedReader entrada = Files.newBufferedReader(ruta, StandardCharsets.ISO_8859_1)) {
|
||||
propiedades.load(entrada);
|
||||
|
||||
try (InputStream is = GestorPropiedad.class.getClassLoader().getResourceAsStream(FICHERO_PROPIEDADES)) {
|
||||
|
||||
if (is == null) {
|
||||
throw new RuntimeException("No se ha podido cargar el fichero de configuración: " + FICHERO_PROPIEDADES);
|
||||
}
|
||||
|
||||
try (BufferedReader entrada = new BufferedReader(new InputStreamReader(is, StandardCharsets.ISO_8859_1))) {
|
||||
propiedades.load(entrada);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al cargar el archivo de propiedades: " + e.getMessage());
|
||||
throw new RuntimeException("Error al cargar el archivo de propiedades: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String get(String clave) {
|
||||
return propiedades.getProperty(clave);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user