static int rows = 0;
static int num = 0;
public static void main(String[] args) {
show(new File(file));
System.out.println("共" + num + "个java文件,共" + rows + "行代码");
}
public static void show(File file) {
File[] fs = file.listFiles();
for (File f : fs) {
if (f.isDirectory()) {
show(f);
} else {
if (f.getName().endsWith(".java")) {
++num;
int row = getRowCount(f);
rows += row;
System.out.println(f.getAbsolutePath() + "(" + row + ")");
}
}
}
}
public static int getRowCount(String src) {
return getRowCount(new File(src));
}
public static int getRowCount(File src) {
int line = 0;
try (BufferedReader file = new BufferedReader(new FileReader(src))) {
while (file.ready()) {
line++;
file.readLine();
}
} catch (Exception e) {
}
return line;
}