コード例 #1
0
 /**
  * Given a file that the preferences are supposedly stored in, this function will try to load the
  * preferences. If the preferences don't exist, or they are incomplete, this will also fill in the
  * missing values, and store the now complete preferences in the file location specified.
  *
  * @param prefFile
  * @throws Exception
  */
 public void init(File prefFile) throws IOException {
   this.prefFile = prefFile;
   if (prefFile.exists()) {
     Properties userProperties = new Properties();
     FileInputStream in = new FileInputStream(prefFile);
     userProperties.load(in);
     in.close();
     for (String key : userProperties.stringPropertyNames()) {
       String val = userProperties.getProperty(key);
       String value = getObject(val, ((Preference) prefs.get(key))).toString();
       Object ovalue = getObject(val, ((Preference) prefs.get(key)));
       Preference p1 = prefs.get(key);
       Preference p2;
       if (p1 != null) {
         p2 = new Preference(p1.name, value, p1.allowed, p1.description);
       } else {
         p2 = new Preference(key, val, Type.STRING, "");
       }
       p2.objectValue = ovalue;
       prefs.put(key, p2);
     }
   }
   save();
 }