Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package birdnest.client.deamon; import birdnest.client.deamon.Utils.HashUtils; import java.io.File; import java.io.IOException; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.io.FileUtils; /** * * @author marcelo */ public class Settings extends Properties { private File currentFile = new File("client.properties"); public Settings() { if (this.currentFile.exists()) { loadSettings(currentFile); } else { loadDefaults(); this.saveSettings(); } } public void saveSettings() { try { this.store(FileUtils.openOutputStream(currentFile), "Birdnest Client Deamon Settings"); } catch (IOException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } } private void loadDefaults() { try { this.setProperty("Port", "9090"); this.setProperty("Password", HashUtils.hashString("BIRDNEST", "MD5")); } catch (Exception ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } } public void loadSettings(File currentFile) { try { this.load(FileUtils.openInputStream(currentFile)); } catch (IOException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } } }