title: Get Files from raw folder in Android
body: <p>I have kept some binary files in raw directory in Android application. I want to access them in the application and create a file from it at runtime. I am going to send this file over network. </p>
  
  <p>How can I refer the raw resources? I have done following code</p>
  
  <pre><code>private File getFileByResourceId(int id, String fileName) throws IOException {
          File file = new File(fileName);
          InputStream ins = ctx.openRawResource(id);
          log.debug(ins.toString());
          log.debug(file.getAbsolutePath());
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          int size = 0;
          // Read the entire resource into a local byte buffer.
          byte[] buffer = new byte[1024];
          while ((size = ins.read(buffer, 0, 1024)) &gt;= 0) {
              outputStream.write(buffer, 0, size);
          }
          ins.close();
          buffer = outputStream.toByteArray();
          FileOutputStream fos = new FileOutputStream(file);
          fos.write(buffer);
          fos.close();
          return file;}
  </code></pre>
  
  <p>But when I try to access this file it gives me permission errors.</p>
  
  <p>Can someone propose a solution?</p>