code: private static File findFileOption(String[] args, String option, String name, boolean needed)
          throws ProblemException, ProblemException {
          File file = null;
          for (int i = 0; i<args.length; ++i) {
              if (args[i].equals(option)) {
                  if (file != null) {
                      throw new ProblemException("You have already specified the "+name+" file!");
                  }
                  if (i+1 >= args.length) {
                      throw new ProblemException("You have to specify a file following "+option+".");
                  }
                  file = new File(args[i+1]);
                  if (file.isDirectory()) {
                      throw new ProblemException("\""+args[i+1]+"\" is not a file.");
                  }
                  if (!file.exists() && needed) {
                      throw new ProblemException("The file \""+args[i+1]+"\" does not exist.");
                  }
  
              }
          }
          if (file == null && needed) {
              throw new ProblemException("You have to specify "+option);
          }
          return file;
      }
docs: Scan the arguments to find an option that specifies a file.