title: Java - Search for files in a directory
body: <p>This is supposed to be simple, but I can't get it - "Write a program that searches for a particular file name in a given directory." I've found a few examples of a hardcoded filename and directory, but I need both the dir and file name to be as entered by the user.</p>
  
  <pre><code>public static void main(String[] args) {
      String fileName = args[0]; // For the filename declaration
      String directory;     
      boolean found;
  
      File dir = new File(directory);
  
      File[] matchingFiles = dir.listFiles(new FilenameFilter() {
          public boolean accept(File dir, String fileName) {
              return true;
          }
      });
  
  }
  </code></pre>