code: private File searchFile(File directory, String pattern) {
          if (!directory.isDirectory()) {
              throw new IllegalArgumentException("Not a directly: "+directory);
          }
          File[] files = directory.listFiles();
          assert files != null; //checked for directly above.
          for (File file : files) {
              if (file.getName().matches(pattern)) return file;
          }
          return null;
      }
docs: File search (easy glob)
  @param directory directory path
  @param pattern   searching file pattern with regular representation
  @return matched file