当前位置:网站首页>统计项目代码行数
统计项目代码行数
2020-11-06 21:40:00 【会开车的架构师】
package com.travelsky.falcon.controller.testPackage.countCode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* 统计指定目录下java文件的行数
* @author wdm
* @date
*/
public class CountFileRow {
private static int total = 0;
private static int fileNum = 1;
/*
* 统计单个文件的行数
*/
public static void singleFile(File file){
FileReader reader = null;
BufferedReader buffer = null;
try {
reader = new FileReader(file);
buffer = new BufferedReader(reader);
String line = null;
while((line=buffer.readLine())!= null){
//去除空格
String trimStr = line.trim();
//如果以/,*开头,就跳过该次循环
if(trimStr.startsWith("/") || trimStr.startsWith("*") || trimStr.length()<=0){
continue;
}else{
total++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* 遍历指定目录下所有的文件
*/
public static void fileTraversal(File directory){
File[] file = directory.listFiles();
for(int i=0; i<file.length; i++){
if(file[i].isDirectory()){ //此对象如果是目录,就递归
fileTraversal(file[i]);
}else{
if(file[i].getName().endsWith(".java")){//判断是否以.java结尾
System.out.println("第"+(++fileNum)+"个文件:\t"+file[i]);
singleFile(file[i]);//统计单个文件的行数
}
}
}
}
public static void main(String[] args) {
File dir = new File("D:\\workspace\\trunk");
fileTraversal(dir);
System.out.println("共"+total+"行代码");
}
}
版权声明
本文为[会开车的架构师]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4629483/blog/4529704
边栏推荐
- Azure data factory (3) integrate azure Devops to realize CI / CD
- Small program introduction to proficient (2): understand the four important files of small program development
- Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
- Discussion on the development practice of aspnetcore, a cross platform framework
- 【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
- Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
- FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Take you to learn the new methods in Es5
- A small goal in 2019 to become a blog expert of CSDN
猜你喜欢

StickEngine-架构12-通信协议

游戏主题音乐对游戏的作用

2020年数据库技术大会助力技术提升

Digital city responds to relevant national policies and vigorously develops the construction of digital twin platform

Diamond standard

How to turn data into assets? Attracting data scientists

检测证书过期脚本

如何在终端启动Coda 2中隐藏的首选项?

给字节的学姐讲如何准备“系统设计面试”

Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
随机推荐
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
What if the front end doesn't use spa? - Hacker News
ERD-ONLINE 免费在线数据库建模工具
大会倒计时|2020 PostgreSQL亚洲大会-中文分论坛议程安排
What is the purchasing supplier system? Solution of purchasing supplier management platform
Git rebase is in trouble. What to do? Waiting line
What knowledge do Python automated testing learn?
How to get started with new HTML5 (2)
C#和C/C++混合编程系列5-内存管理之GC协同
事务的本质和死锁的原理
From overseas to China, rancher wants to do research on container cloud market
快速排序为什么这么快?
An article will take you to understand SVG gradient knowledge
What are the common problems of DTU connection
Analysis of ThreadLocal principle
美团内部讲座|周烜:华东师范大学的数据库系统研究
C# 调用SendMessage刷新任务栏图标(强制结束时图标未消失)
Diamond standard
The method of realizing high SLO on large scale kubernetes cluster