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
| public Properties loadProperties() throws IOException {
Properties properties = new Properties();
// Chargement depuis un fichier dans le classpath :
InputStream stream = ClassLoader.getSystemResourceAsStream("/packageName/default.properties");
try {
properties.load(stream);
} finally {
stream.close();
}
// Chargement depuis un fichier utilisateur (s'il existe) :
File configFile = new File( System.getProperty("user.home"), ".tonApllication.config" );
if (configFile.exists()) {
stream = new FileInputStream(configFile);
try {
properties.load(stream);
} finally {
stream.close();
}
}
return properties;
} |
Partager