Code example for BufferedInputStream

        if (!file.isFile()) {
            return null; 
        InputStream is = null;
        try { 
            is = new BufferedInputStream(new FileInputStream(file));
            return (X509Certificate) CERT_FACTORY.generateCertificate(is);
        } catch (IOException e) {
            return null; 
        } catch (CertificateException e) {
            // reading a cert while its being installed can lead to this. 
            // just pretend like its not available yet. 
            return null; 
        } finally { 
    private void writeCertificate(File file, X509Certificate cert)
            throws IOException, CertificateException { 
Stop searching for code, let great code find you!  Add Codota to your java IDE