package class_1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class CodeCounter {
private static long codeLine ;
public void counter(String filePath){
File file = new File(filePath);
File[] files = file.listFiles();
int length = files.length;
for(int i = 0;i<length;i++){
if(files.isFile()){
if(files.getName().toLowerCase().endsWith(".java")){
read(files.getPath());
}
}else{
counter(files.getPath());
}
}
}
public static void read(String filePath){
try{
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line = null;
int count = 0;
while((line = br.readLine())!=null){
codeLine ++;
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
CodeCounter cc = new CodeCounter();
cc.counter("D://TDDOWNLOAD//Movie//Annotation讲解//031603_【第16章:Annotation】_反射与Annotation//代码");
System.out.println(cc.codeLine);
}
}