-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathManejadorProperties.java
More file actions
71 lines (57 loc) · 1.72 KB
/
Copy pathManejadorProperties.java
File metadata and controls
71 lines (57 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* Clase usada para leer archivos properteis usando un
* patrón Singleton
* @author Inazio
*
*/
public class ManejadorProperties {
// Propiedades
private String rutaFichero = "fichero.properties";
private static Properties propiedades = null;
// Constructor
private ManejadorProperties() throws FileNotFoundException, IOException {
propiedades = new Properties();
propiedades.load(new FileReader(rutaFichero));
}
// Métodos
/**
* Lee una propiedad
* @param miClave
* @return Valor de la propiedad
* @throws FileNotFoundException
* @throws IOException
*/
public static String leerPropiedad(String miClave) throws FileNotFoundException, IOException {
if (propiedades == null) {
new ManejadorProperties();
}
String resultado = "";
resultado = propiedades.getProperty(miClave);
return resultado;
}
/**
* Devuelve todas las propiedades del archivo de configuración
* @return Mapa de clave valor con las propiedades correspondientes
* @throws FileNotFoundException
* @throws IOException
*/
public Map<String, String> leerTodasLasPropiedades() throws FileNotFoundException, IOException {
if (propiedades == null) {
new ManejadorProperties();
}
Map<String, String> listadoPropiedades = new HashMap<String, String>();
Enumeration<Object> claves = propiedades.keys();
while (claves.hasMoreElements()) {
Object clave = claves.nextElement();
listadoPropiedades.put(clave.toString(), propiedades.get(clave).toString());
}
return listadoPropiedades;
}
}