0

I am facing java.io.EOFException when i call load method by passing keystore. I have .jks file. File is loaded correctly and i could read and print the data from file.

tried with different .jks files tried to modify the code here and there by passing password as null etc.

     try {

        KeyStore keyStore  = KeyStore.getInstance("JKS");
        logger.info("No Issues till line 115");
        FileInputStream keyFileStream = new            
        FileInputStream("C:\\Users\\Path\\Certificates\\default.jks");

        // printing the data from the file to check if file is loaded 
        //with data
        int i=0;
        while((i=keyFileStream.read())!=-1){
            logger.info("Reading File Data: "+(char)i);
        }

        try {
            /*** Below line gives EOF Exception ***/
            keyStore.load(keyFileStream, "password".toCharArray()); 
            logger.info("Failed to print this line" + keyStore.size());
        } finally {
            keyFileStream.close();
        }
         }
            catch (Throwable t){
                  logger.error("Exception occured with "+t,t);
            }

Actual:

Exception occured with java.io.EOFException

Jaffar
  • 3
  • 2
  • Usually, if you read from a stream the data is gone. Either you need to [copy the stream](https://stackoverflow.com/questions/5923817/how-to-clone-an-inputstream) or avoid checking if the stream contains data in first place – Roman Vottner Aug 08 '19 at 15:39
  • Thank You for your suggestion. I used different API – Jaffar Aug 15 '19 at 08:41

0 Answers0