lwcode6
/**
 * @Classname CustBankcardServiceImpl
 * @Description 计算项目代码量(行数)
 * @Date 2019/11/04 14:24
 * @Created by lw
 */
public class CalcCodeNum {

   public static void main(String[] args) throws IOException {
      // java代码
      int java_num = getProjectFileNumber(new File("D:\\lw\\work_space\\yxhd\\lcs\\lcs-service\\src\\main\\java\\io\\kyoto"), ".java");

      // resource目录
      // xml
      int xml_num = getProjectFileNumber(new File("D:\\lw\\work_space\\yxhd\\lcs\\lcs-service\\src\\main"), ".xml");
      // properties
      int properties_num = getProjectFileNumber(new File("D:\\lw\\work_space\\yxhd\\lcs\\lcs-service\\src\\main"), ".properties");
      System.out.println("java:" + java_num);
      System.out.println("xml:" + xml_num);
      System.out.println("properties:" + properties_num);
      System.out.println("total:" + (java_num + xml_num + properties_num));
   }

   /**
     * 递归获取文件中代码行数
     * */
   private static int getProjectFileNumber(File file, String endsWith) throws IOException{
      int number = 0;
      if (file.exists()) {
         if (file.isDirectory()) {
            for (File subFile : file.listFiles()) {
               number += getProjectFileNumber(subFile, endsWith);
            }
         } else if (file.isFile() && file.getName().endsWith(endsWith)) {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            while (br.readLine() != null) {
               number += 1;
            }
         } else {
            System.out.println("===" + file.getAbsolutePath());
         }
      }
      return number;
   }

}

 

分类:

技术点:

相关文章:

  • 2021-11-09
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2021-12-18
  • 2021-12-15
猜你喜欢
  • 2021-09-10
  • 2021-06-08
  • 2021-10-06
  • 2021-12-21
  • 2021-06-08
  • 2022-12-23
相关资源
相似解决方案