package com.project.tools; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; /** * author qurong * 2019/10/24 09:21 */ public class CodeLine { private static long count=0; private static BufferedReader br; public static void main(String[] args) throws Exception { File f=new File("D:\\project"); go(f); System.out.println(count); } private static void go(File f) throws Exception { if (f.isDirectory()) { File[] files = f.listFiles(); if (files!=null) { for (File file : files) { go(file); } } }else { if (f.getName().endsWith(".java")) { br=new BufferedReader(new FileReader(f)); while (br.readLine()!=null) { count++; } } } } }