KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > importscrubber > Settings


1 package net.sourceforge.importscrubber;
2
3 import java.io.*;
4 import java.util.Properties JavaDoc;
5
6 public class Settings
7 {
8     private String JavaDoc _appName;
9     private Properties JavaDoc _props;
10
11     public Settings(String JavaDoc 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 JavaDoc();
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 JavaDoc exception) { }
34     }
35
36     public void put(String JavaDoc pKey, String JavaDoc pValue)
37     {
38         _props.put(pKey, pValue);
39     }
40
41     public String JavaDoc get
42         (String JavaDoc 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