1 package net.sourceforge.importscrubber; 2 3 import java.io.*; 4 import java.util.Properties ; 5 6 public class Settings 7 { 8 private String _appName; 9 private Properties _props; 10 11 public Settings(String appName) 12 { 13 _appName = appName; 14 File homeDir = new File(System.getProperty("user.home")); 15 if(!homeDir.exists()) { 16 homeDir.mkdirs(); 17 } 18 File appDir = new File(System.getProperty("user.home"), _appName); 19 if(!appDir.exists()) { 20 appDir.mkdir(); 21 } 22 load(); 23 } 24 25 public void load() 26 { 27 _props = new Properties (); 28 try { 29 File appDir = new File(System.getProperty("user.home"), _appName); 30 BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(appDir, _appName))); 31 _props.load(in); 32 in.close(); 33 } catch(Exception exception) { } 34 } 35 36 public void put(String pKey, String pValue) 37 { 38 _props.put(pKey, pValue); 39 } 40 41 public String get 42 (String pKey) 43 { 44 return _props.getProperty(pKey); 45 } 46 47 public void save() throws IOException 48 { 49 File appDir = new File(System.getProperty("user.home"), _appName); 50 BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(appDir, _appName))); 51 _props.store(out, "Importscrubber"); 52 out.close(); 53 } 54 55 } 56 | Popular Tags |