code: public void copyResource(String name, String destinationFilename) {
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          if (classLoader == null) {
              String error = "Can not obtain classloader instance";
              throw new IllegalStateException(error);
          }
          try (InputStream stream = classLoader.getResourceAsStream(name)) {
              if (stream == null) {
                  String error = "Could not copy file, source file not found: " + name;
                  throw new IllegalStateException(error);
              }
              Path path = Paths.get(destinationFilename);
              FileUtils.copyInputStreamToFile(stream, path.toFile());
          } catch (IOException e) {
              throw new GeneratorException("Could not copy %s", e, name);
          }
      }
docs: Copy a classpath resource to the given location on a filesystem.