Code:
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.util.Enumeration;

public class GetCrts {

  public static void main( String[] args ) throws Exception {
    final String keyStore = "acme";
    final String keyStorePass = "danger";
    final String keyPass = "password";

    // load information into a keystore
    java.security.KeyStore Keys = java.security.KeyStore.getInstance( "JKeys" );
    java.io.FileInputStream FSKeys = new java.io.FileInputStream( keyStore );
    java.io.BufferedInputStream Buffkeys = new java.io.BufferedInputStream( FSKeys );
    Keys.load( Buffkeys, keyStorePass.toCharArray() );

    // list aliases in the keystore
    java.io.FileOutputStream MyFoutStrem = null;
    for( java.util.Enumeration theAliases = Keys.aliases(); theAliases.hasMoreElements(); ) {
      String Str = (String) theAliases.nextElement();
      java.security.cert.Certificate cert = Keys.getCertificate( Str );
      ByteUtils.saveBytesToFile( Str + ".cer", cert.getEncoded() );
      ByteUtils.saveBytesToFile( Str + ".pubkey", cert.getPublicKey().getEncoded() );
      java.security.PrivateKey privateKey = (java.security.PrivateKey) Keys.getKey( Str, keyPass.toCharArray() );
      ByteUtils.saveBytesToFile( Str + ".privKey", privateKey.getEncoded() );
      System.out.println( " certificate info " + Str );
      System.out.println( cert );
    }
  }
}