#vulnerable code 
                                private void saveTrustedHost( String fingerprint ) throws IOException
    {
        this.fingerprint = fingerprint;

        logger.info( "Adding %s as known and trusted certificate for %s.", fingerprint, serverId );
        createKnownCertFileIfNotExists();

        assertKnownHostFileWritable();
        BufferedWriter writer = new BufferedWriter( new FileWriter( knownHosts, true ) );
        writer.write( serverId + " " + this.fingerprint );
        writer.newLine();
        writer.close();
    } 
                            #location 13 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                private void saveTrustedHost( String fingerprint ) throws IOException
    {
        this.fingerprint = fingerprint;

        logger.info( "Adding %s as known and trusted certificate for %s.", fingerprint, serverId );
        createKnownCertFileIfNotExists();

        assertKnownHostFileWritable();
        try ( BufferedWriter writer = new BufferedWriter( new FileWriter( knownHosts, true ) ) )
        {
            writer.write( serverId + " " + this.fingerprint );
            writer.newLine();
        }
    }