View the number of lines of code

To get the company of copyright, there is one item asked how many lines of code, write a code to help me count

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;
    }
}
Published 127 original articles · won praise 16 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_33321609/article/details/103481671