1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.util;
14
15 import java.io.File;
16 import java.io.FileInputStream;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
19 import java.util.Properties;
20
21
22
23
24
25
26 public class Preferences extends Properties {
27
28
29 protected String configFileName = ".config";
30
31
32
33
34 public Preferences(String configFileName) {
35 this.configFileName = configFileName;
36 }
37
38
39
40
41
42
43 public void save() throws IOException {
44 FileOutputStream out = new FileOutputStream(getConfigFile());
45 try {
46 super.store(out, "Configuration");
47 } finally {
48 out.close();
49 }
50 }
51
52
53
54
55
56
57 public void load() throws IOException {
58 File configFile = getConfigFile();
59 if (configFile.exists()) {
60 FileInputStream in = new FileInputStream(configFile);
61 try {
62 load(in);
63 } finally {
64 in.close();
65 }
66 }
67 }
68
69
70
71
72
73
74 public File getConfigFile() {
75 File f = new File(System.getProperty("user.home"));
76 return new File(f, getConfigFileName());
77 }
78
79
80
81
82
83
84 public void setConfigFileName(String fileName) {
85 this.configFileName = fileName;
86 }
87
88
89
90
91
92
93 public String getConfigFileName() {
94 return configFileName;
95 }
96
97 }