title: How to run a Java program on all files in a directory from command line
body: <p>I've got this java program which is currently programmed to take in a filename as an argument from command line, open it and then read it. I want to configure it so I can pass it a directory name and the program will execute on the files in the directory. Not really sure how to go about it. This is my code currently:</p>
  
  <pre><code>static XMLInputFactory factory = XMLInputFactory.newInstance(); 
  XMLEventReader reader = null;  
  XMLEventFactory eventFactory = null;
  
  public XMLTrimmer(File ifp) throws XMLStreamException, FileNotFoundException {
      this(new FileInputStream(ifp));
  }
  
  public XMLTrimmer(InputStream str) throws XMLStreamException, FileNotFoundException {
      try {
          reader = factory.createXMLEventReader(str);
      } catch (XMLStreamException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>In main it goes like this:</p>
  
  <pre><code>public static void main(String args[]) throws IOException, XMLStreamException {
  
      File readFile = new File(args[0]);
  
      XMLTrimmer xr = new XMLTrimmer(readFile);
  </code></pre>
  
  <p>please let me know, any help is appreciated.</p>