公司要弄著作权,有一项是问有多少行代码,写了个代码,来帮我数数
public class Test {
public static void main(String[] args) throws Exception {
show(new File("D:\\work\\idea\\skigit\\ski191127"));
}
public static int show(File file) throws Exception {
if (file.isFile()) {
if (file.getName().indexOf("java") == -1 &&
file.getName().indexOf("js") == -1 &&
file.getName().indexOf("ftl") == -1 &&
file.getName().indexOf("css") == -1) {
return 0;
}
int line = 0;
FileReader reader = new FileReader(file);
BufferedReader bf = new BufferedReader(reader);
while (bf.readLine() != null) {
line++;
}
System.out.println(file.toString() + ":" + line);
return line;
}
int line = 0;
for (File f : file.listFiles()) {
line += show(f);
}
System.out.println(file.toString() + ":" + line);
return line;
}
}