Here you can find the source of getFileNames(File path, Vector
public static void getFileNames(File path, Vector<String> result) throws Exception
//package com.java2s; /*//from w w w . j a va 2s . co m * Biocep: R-based Platform for Computational e-Science. * * Copyright (C) 2007-2009 Karim Chine - karim.chine@m4x.org * * Copyright (C) 2007 EMBL-EBI-Microarray Informatics * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; import java.io.FileReader; import java.util.Vector; public class Main { public static void getFileNames(File path, Vector<String> result) throws Exception { File[] files = path.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory() || pathname.toString().toLowerCase().endsWith(".java") || pathname.toString().toLowerCase().endsWith(".r") || pathname.toString().toLowerCase().endsWith("build.xml"); } }); if (files == null) return; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { getFileNames(files[i], result); } else { String name = files[i].getAbsolutePath(); System.out.println(name + " --> " + countLines(name)); result.add(name); } } } public static int countLines(String fileName) throws Exception { BufferedReader br = new BufferedReader(new FileReader(fileName)); int counter = 0; while ((br.readLine()) != null) ++counter; return counter; } }