title: java.security.AccessControlException: access denied (java.io.FilePermission
body: <p>i am creating an app on google app engine java in which i have to read content of a static file.there is a file in war directory named as myrsakey11.pk8 .</p>
  
  <p>my code segment for reading the file is </p>
  
  <pre><code>public static PrivateKey getPrivateKey(String privKeyFileName) throws IOException {
            File privKeyFile = new File(privKeyFileName);
            FileInputStream fis = new FileInputStream(privKeyFile);
            DataInputStream dis  = new DataInputStream(fis);
  
            byte[] privKeyBytes = new byte[(int) privKeyFile.length()];
            try {
              dis.read(privKeyBytes);
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
            dis.close();
            fis.close();
  
            String BEGIN = "-----BEGIN PRIVATE KEY-----";
            String END = "-----END PRIVATE KEY-----";
            String str = new String(privKeyBytes);
  
            if (str.contains(BEGIN) &amp;&amp; str.contains(END)) {
              str = str.substring(BEGIN.length(), str.lastIndexOf(END));
            }
  
            KeyFactory fac;
          try {
              fac = KeyFactory.getInstance("RSA");
  
               EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decode(str));
                return fac.generatePrivate(privKeySpec);
  
          } catch (NoSuchAlgorithmException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (Base64DecoderException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (InvalidKeySpecException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
           return null;
      }
  </code></pre>
  
  <p>and in this function i am passing string "/myrsakey11.pk8"</p>
  
  <p>and the full error log i am getting is</p>
  
  <pre><code>java.security.AccessControlException: access denied (java.io.FilePermission /myrsakey11.pk8 read)
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)
      at java.security.AccessController.checkPermission(AccessController.java:567)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
      at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:56)
      at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
      at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:133)
      at org.ritesh.HelloWorldServlet.getPrivateKey(HelloWorldServlet.java:129)
      at org.ritesh.HelloWorldServlet.doGet(HelloWorldServlet.java:110)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:326)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
      at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
      at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
      at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
      at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
      at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
      at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
      at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
      at java.lang.Thread.run(Thread.java:679)
  </code></pre>
  
  <p>can any one please tell me how to rectify this error??</p>