View Javadoc

1   package sk.stuba.fiit.foo07.genex.common;
2   
3   /**
4    * @author palo
5    * 
6    */
7   import java.io.FileInputStream;
8   import java.io.FileOutputStream;
9   import java.io.IOException;
10  import java.util.Properties;
11  
12  public class SettingsHelper {
13  
14      final static String settingsFilename = "genex.properties";
15      static Properties Props;
16  
17      public static void setSetting(String key, String value) throws IOException {
18          FileInputStream fis = new FileInputStream(settingsFilename);
19          Props.load(fis);
20          fis.close();
21          Props.setProperty(key, value);
22          FileOutputStream fos = new FileOutputStream(settingsFilename);
23          Props.store(fos, "Genex settings");
24          fos.close();
25      }
26  
27      public static String getSetting(String key) throws IOException {
28          FileInputStream fis = new FileInputStream(settingsFilename);
29          Props.load(fis);
30          fis.close();
31  
32          return Props.getProperty(key);
33      }
34  
35      static {
36          Props = new Properties();
37      }
38  }