code: public static File copyResourceToLocalFile(String sourceResource, String destFileName) throws Exception {
          try {
              Resource keystoreFile = new ClassPathResource(sourceResource);
              InputStream in = keystoreFile.getInputStream();
  
              File outKeyStoreFile = new File(destFileName);
              FileOutputStream fop = new FileOutputStream(outKeyStoreFile);
              byte[] buf = new byte[512];
              int num;
              while ((num = in.read(buf)) != -1) {
                  fop.write(buf, 0, num);
              }
              fop.flush();
              fop.close();
              in.close();
              return outKeyStoreFile;
          } catch (IOException ioe) {
              throw new Exception("Could not copy keystore file: " + ioe.getMessage());
          }
      }
docs: Copies file from a resource to a local temp file
  
  @param sourceResource
  @return Absolute filename of the temp file
  @throws Exception