KeyManagementException, NoSuchAlgorithmException, SvcLogicException {
 
         /* Point to the certificate */
-        FileInputStream fs = new FileInputStream(certFile);
+        try(FileInputStream fs = new FileInputStream(certFile)){
+               /* Generate a certificate from the X509 */
+               CertificateFactory cf = CertificateFactory.getInstance("X.509");
+               X509Certificate cert = (X509Certificate) cf.generateCertificate(fs);
 
-        /* Generate a certificate from the X509 */
-        CertificateFactory cf = CertificateFactory.getInstance("X.509");
-        X509Certificate cert = (X509Certificate) cf.generateCertificate(fs);
+               /* Create a keystore object and load the certificate there */
+               KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
+               keystore.load(null, null);
+               keystore.setCertificateEntry("cacert", cert);
 
-        /* Create a keystore object and load the certificate there */
-        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
-        keystore.load(null, null);
-        keystore.setCertificateEntry("cacert", cert);
+               SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build();
+               SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
+                       SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
 
-        SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build();
-        SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
-                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
-
-        httpClient = HttpClients.custom().setSSLSocketFactory(factory).build();
+               httpClient = HttpClients.custom().setSSLSocketFactory(factory).build();
+        }
     }
 
     /**
 
                 doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " +
                         "is not of type .sls");
             }
-            InputStream in = new FileInputStream(file);
-            byte[] data = new byte[(int) file.length()];
-            in.read(data);
-            String str = new String(data, "UTF-8");
-            in.close();
-            String slsWithoutExtn = stripExtension(slsFile);
-            constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/").
+            try(InputStream in = new FileInputStream(file)){
+                byte[] data = new byte[(int) file.length()];
+                in.read(data);
+                String str = new String(data, "UTF-8");
+                String slsWithoutExtn = stripExtension(slsFile);
+                constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/").
                     append(slsFile).append("; ").append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '").
                     append(applyTo).append("' state.apply ").append(slsWithoutExtn).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT);
-
+            }
             logger.info("Command to be executed on server : " + constructedCommand.toString());
 
         } catch (FileNotFoundException e) {