Пример #1
0
  /**
   * attempts to load the saved parameters from the file so that the user does not have to reenter
   * all the information.
   *
   * @return Properties loaded from file or null.
   */
  private Properties loadParametersFromFile() {
    Properties loadedProperties = null;

    if (savedOptionsFile.exists() && savedOptionsFile.canRead()) {
      synchronized (savedOptionsFile) {
        try {
          FileInputStream fis = new FileInputStream(savedOptionsFile);
          loadedProperties = new Properties();
          loadedProperties.load(fis);
          fis.close();
        } catch (FileNotFoundException e) {
          assert false : "File not found after existance verified";
          ApplicationRunner.handleException(
              "Unable to load user " + "parameters. Default values will be used.\n" + e);
        } catch (IOException e) {
          assert false : "Bad data in parameters file";
          ApplicationRunner.handleException(
              "Unable to load user " + "parameters. Default values will be used.\n" + e);
        }
      }
    }
    return loadedProperties;
  }
Пример #2
0
 /**
  * saves the parameters to a file so that they can be used again next time the application starts.
  */
 private void saveParametersToFile() {
   try {
     synchronized (savedOptionsFile) {
       if (savedOptionsFile.exists()) {
         savedOptionsFile.delete();
       }
       savedOptionsFile.createNewFile();
       FileOutputStream fos = new FileOutputStream(savedOptionsFile);
       parameters.store(fos, "Denny's DVDs configuration");
       fos.close();
     }
   } catch (IOException e) {
     ApplicationRunner.handleException(
         "Unable to save user parameters to file. "
             + "They wont be remembered next time you start.");
   }
 }