统计项目代码行数

作者:源码世界时间:2014-03-13分类:程序员碎语评论:0浏览:5990
public static int getProjectFileNumber(File file, String endsWith) throws IOException {
        int number = 0;
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File subFile : file.listFiles()) {
                    number += getProjectFileNumber(subFile, endsWith);
                }
            } else if (file.isFile() && file.getName().endsWith(endsWith)) {
                BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                while (br.readLine() != null) {
                    number += 1;
                }
            } else {
                System.out.println("===" + file.getAbsolutePath());
            }
        }
        return number;
    }

    public static void main(String[] args) throws IOException {
        //用法示例
        int num = Test.getProjectFileNumber(new File("D:\\Workspaces10\\web\\src\\com"), ".java");
        System.out.println(num);
    }
标签:Java  
返回顶部
分享按钮