public void save() throws java.io.IOException {
    if (prefsFile == null)
      throw new UnsupportedOperationException("XMLStore is read-only");

      // get temporary file to write to
    File prefTemp;
    String parentFilename = prefsFile.getParent();
    if (parentFilename == null) {
      prefTemp = File.createTempFile("pref", ".xml");
    } else {
      File parentFile = new File(parentFilename);
      prefTemp = File.createTempFile("pref", ".xml", parentFile);
    }
    prefTemp.deleteOnExit();

    // save to the temp file
    FileOutputStream fos = new FileOutputStream( prefTemp, false);
    save( fos);
    fos.close();

    // success - rename files
    Path xmlBackup = Paths.get(prefsFile.getAbsolutePath() + ".bak");
    Path prefsPath = prefsFile.toPath();
    if (Files.exists(prefsPath))
        Files.move(prefsPath, xmlBackup, StandardCopyOption.REPLACE_EXISTING);
    Files.move(prefTemp.toPath(), prefsFile.toPath(),
            StandardCopyOption.REPLACE_EXISTING);
  }
public void save ( ) throws java . io . IOException { if ( prefsFile == null ) throw new UnsupportedOperationException ( "XMLStore is read-only" ) ; File prefTemp ; String parentFilename = prefsFile . getParent ( ) ; if ( parentFilename == null ) { prefTemp = File . createTempFile ( "pref" , ".xml" ) ; } else { File parentFile = new File ( parentFilename ) ; prefTemp = File . createTempFile ( "pref" , ".xml" , parentFile ) ; } prefTemp . deleteOnExit ( ) ; FileOutputStream fos = new FileOutputStream ( prefTemp , false ) ; save ( fos ) ; fos . close ( ) ; Path xmlBackup = Paths . get ( prefsFile . getAbsolutePath ( ) + ".bak" ) ; Path prefsPath = prefsFile . toPath ( ) ; if ( Files . exists ( prefsPath ) ) Files . move ( prefsPath , xmlBackup , StandardCopyOption . REPLACE_EXISTING ) ; Files . move ( prefTemp . toPath ( ) , prefsFile . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; }
Save the current state of the Preferences tree to disk, using the
original filename. The XMLStore must have been constructed from a
writeable XML file.
@throws UnsupportedOperationException: if XMLStore was created from createFromResource.
@throws java.io.IOException on read error