Do you need to explicity close a Java KeyStore input stream?

后端 未结 3 525
小蘑菇
小蘑菇 2021-01-14 14:23

When reading in a KeyStore using a FileInputStream as follows, does one need to explicitly close the input-steam to stop system resources being wasted ?

File         


        
3条回答
  •  广开言路
    2021-01-14 14:56

    Yes, try this test

        FileInputStream fin = new FileInputStream("keystore.jks") {
            public void close() throws java.io.IOException {
                System.out.println("close");
            }
        };
        KeyStore keystore = KeyStore.getInstance("JKS");
        keystore.load(fin, "changeit".toCharArray());
    

    and you will see that close() is not called

提交回复
热议问题