[Properties] lecture d'un fichier properties
Bonsoir
voila mon objectif est d'avoir acces aux couples (key,value) d'un fichier properties
j'ai une classe java dont voici le code
Code:
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
|
import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class TestProperties {
public static String CONFIGURATION_FILE = "monfichier.properties";
public static void init() throws FileNotFoundException,IOException{
System.out.println("appel methode init");
Properties prop = new Properties() ;
File fProp = new File(CONFIGURATION_FILE) ;
// Charge le contenu de ton fichier properties dans un objet Properties
FileInputStream stream = new FileInputStream(fProp) ;
prop.load(stream) ;
//System.out.println(prop.getProperty("toto"));
}
public static void main(String[] args){
TestProperties test =new TestProperties();
try{
test.init();
}
catch(FileNotFoundException fb){
fb.getMessage();
}
catch(IOException io){
io.getMessage();
}
}
} |
ma question est la suivante : comment est ce que je peux acceder aux valeurs de mon fichier properties à partir d'une autre classe java de mon application ?
merci d'avance