//Writing values to the config file
File configFile = new File("config.properties");
try {
Properties props = new Properties();
props.setProperty("host", "www.codejava.net");
FileWriter writer = new FileWriter(configFile);
props.store(writer, "host settings");
writer.close();
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
//Reading values from the config file
File configFile = new File("config.properties");
try {
FileReader reader = new FileReader(configFile);
Properties props = new Properties();
props.load(reader);
String host = props.getProperty("host");
System.out.print("Host name is: " + host);
reader.close();
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
No comments:
Post a Comment