之前学IO流,写了一个一段小代码,用来计算纯净代码的行数。去注释去空格
import java.io.*;
/**
* 去除注释后的代码行数,去除startWith"/"," *","(空字符,表示换行,用equals)"
*/
public class TestPureLine {
public static void main(String[] args) {
//1.File对象封装路径
//之前项目的代码行数
File path = new File("D:\\IDEA\\EclipseWorkspace");
System.out.println(getPureLine(path));//22293精简以后的数量:15331
//现在项目的代码行数
File nowPath = new File("D:\\IDEA\\workspace");
System.out.println(getPureLine(nowPath));//代码8029,精简以后:3216
//一个文件的测试
File testPath = new File("D:\\IDEA\\workspace\\test1");
System.out.println(getPureLine(testPath));//13
}
/**
* 去除注释后的代码行数
*
* @param path
* @return
*/
private static Integer getPureLine(File path) {