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:
Then store the keystore to the output stream fos and close the output stream:
FileOutputStream fos = new FileOutputStream(storeFile);
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.
When I create a test program I can delete the newly generated KeyStore file so the close() does actually close the file. Can you create and publish a stand alone test harness that demonstrates the problem? Please indicate the OS and JDK version involved.