Filter out files from directory--Java

  private void process(String path, FileWriter fw) throws Exception {
    FilenameFilter filter = new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.endsWith(".xml");
      }
    };

    File dir = new File(path);
    String[] children = dir.list(filter);

    for (int i = 0; i < children.length; i++) {
      // Get filename of file or directory
      String filename = children[i];
      System.out.println(filename);
      File file = new File(path + "\\" + filename);
      processFile(file, fw);
    }
  }

你可能感兴趣的:(java,xml)