java通过IO流统计工程里代码的(.java)行数
import java.io.*;
public class _统计工程里代码的java行数 {
private static int count = 0;
public static void main(String[] args) throws IOException {
File file = new File("D:\\JAVASE");
TongJiDemo(file);
System.out.println(count);
}
public static void TongJiDemo(File file) throws IOException {
//判断是否为文件夹
if (file.isDirectory()) {
File[] files = file.listFiles();
//遍历数组
for (File f : files) {
TongJiDemo(f);
}
} else if (file.getName().endsWith(".java")) {
//通过缓冲流对象的文件字符输入流对象来读取数据
BufferedReader br = new BufferedReader(new FileReader(file));
//循环读取
while (br.readLine() != null) {
count++;
}
}
}
}