开发中可能常用到统计代码行数, 统计比较准确,可以分别统计注释,空行,和有效代码。
package com.xxx;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class CodeCounter {
public static long totalCodeCount;
public static long totalBlackCount;
public static long totalRemarkCount;
public static void main(String[] args) throws IOException {
String path = "xxxxx/app/src/main/java";
File projectFile = new File(path);
countDir(projectFile);
System.out.println("--------------总行数:" + (totalCodeCount + totalBlackCount + totalRemarkCount));
System.out.