title: Adding certificate into cacerts file
body: <p>I wanna add my certificate into cacerts keystore by code, i'm doing it as in snippet below. But i getting FileNotFoundException(access is denied).
  I think what that happening because i'm doing that without administrator permissions.
  So, how can i fix it?</p>
  
  <pre><code>package sertificating;
  
  import java.io.*;
  import java.security.KeyStore;
  import java.security.cert.Certificate;
  import java.security.cert.CertificateFactory;
  
  
  /**
   * Created by bugakov on 23.11.2016.
   */
  public class Sertificating {
  
      public static void main(String[] argv) throws Exception {
          String certfile = "C:/Users/bugakov/IdeaProjects/school/sertificating/mycert.crt"; 
          String keystorepath=System.getProperties().get("java.home")+"/lib/security/cacerts";
          FileInputStream is = new FileInputStream(keystorepath);
          KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
          keystore.load(is, "changeit".toCharArray());
          String alias = "mycert.crt";
          char[] password = "changeit".toCharArray();
          CertificateFactory cf = CertificateFactory.getInstance("X.509");
          InputStream certstream = fullStream(certfile);
          Certificate certs = cf.generateCertificate(certstream);
          File keystoreFile = new File(keystorepath);
          FileInputStream in = new FileInputStream(keystoreFile);
          keystore.load(in, password);
          in.close();
          keystore.setCertificateEntry(alias, certs);
          FileOutputStream out = new FileOutputStream(keystoreFile);
          keystore.store(out, password);
          out.close();
  
      }
  
      private static InputStream fullStream(String fname) throws IOException {
          FileInputStream fis = new FileInputStream(fname);
          DataInputStream dis = new DataInputStream(fis);
          byte[] bytes = new byte[dis.available()];
          dis.readFully(bytes);
          ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
          return bais;
      }
  }
  </code></pre>
  
  <p>Exception what I getting looks like this:</p>
  
  <pre><code>Exception in thread "main" java.io.FileNotFoundException: C:\Program Files\Java\jdk1.8.0_102\jre\lib\security\cacerts (Access is denied)
  </code></pre>
  
  <p>at this row</p>
  
  <pre><code>FileOutputStream out = new FileOutputStream(keystoreFile);
  </code></pre>