4 Replies Latest reply: Oct 22, 2010 6:53 AM by 807116 RSS

    Closing a KeyStore file

      My apologies if this is not a well-formed post. It is my first time posting on a java forum, and I tried to find a relevant topic heading among the many available - I figured that creating keystores and certificates for SSL connections could be considered networking-related.

      I am using the KeyStore class to create a collection of keys and certificates. Within my program I want to:
      - create a new keystore
      - set key and certificate entries
      - add the keystore file to a zip file and delete the original keystore file

      Create an empty keystore:
                newKS.load(null, password.toCharArray());

      Then store the keystore to the output stream fos and close the output stream:
                FileOutputStream fos = new FileOutputStream(storeFile);
                newKS.store(fos, password.toCharArray());

      However, this does not close the file storeFile, and I am therefore unable to delete it within my program. I think this is probably a simple issue, but I have not been able to figure out how to close and delete the keystore files within my program. From what I understand you load KeyStores from input streams and store them to output streams but closing the streams does not close the files..? Clarification/assistance would be greatly appreciated. I'm probably just missing something simple.