Computer Prog
Computer Prog
}
- This file will be used to store and retrieve configuration properties.
- This declares a Properties object that will be used to manage the key-value pairs of configuration settings.
public ConfigManager() {
loadConfig();
}
- It initializes a new instance of the class.
- This calls the loadConfig method to load the configuration from the properties file.
properties.load(input);
// File might not exist yet; this is expected for first run
}
- is responsible for loading the configuration from the properties file.
public void saveConfig() {
properties.store(output, null);
ex.printStackTrace();
}
- that is responsible for saving the properties to the configuration file.
public void setRememberedUser(String username) {
properties.setProperty("rememberedUser", username);
saveConfig();
- This calls the saveConfig method to save the updated properties to the configuration file.
public String getRememberedUser() {
return properties.getProperty("rememberedUser");
}
- This defines a public method named getRememberedUser that returns a string.
public void clearRememberedUser() {
properties.remove("rememberedUser");
saveConfig();
}
- This removes the property with the key "rememberedUser" from the properties object.
summary - The ConfigManager class manages configuration settings in a properties file. It
can load and save configurations, set, retrieve, and clear a remembered username. The
class uses Java's Properties for storing settings and includes exception handling for file
operations to ensure robustness.