当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- DRF JWT authentication module and self customization
- 美团内部讲座|周烜:华东师范大学的数据库系统研究
- Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
- Details of dapr implementing distributed stateful service
- What are the criteria for selecting a cluster server?
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
- CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
- Asp.Net Core learning notes: Introduction
- 大会倒计时|2020 PostgreSQL亚洲大会-中文分论坛议程安排
猜你喜欢

Multi robot market share solution

The importance of big data application is reflected in all aspects

【自学unity2d传奇游戏开发】地图编辑器

【:: 是什么语法?】

嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌

Share with Lianyun: is IPFs / filecoin worth investing in?

Who says cat can't do link tracking? Stand up for me

What is the purchasing supplier system? Solution of purchasing supplier management platform

事务的隔离级别与所带来的问题

C + + and C + + programmers are about to be eliminated from the market
随机推荐
JNI-Thread中start方法的呼叫與run方法的回撥分析
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
The legality of IPFs / filecoin: protecting personal privacy from disclosure
美团内部讲座|周烜:华东师范大学的数据库系统研究
An article will take you to understand CSS3 fillet knowledge
Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
Details of dapr implementing distributed stateful service
事务的本质和死锁的原理
【学习】接口测试用例编写和测试关注点
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
使用 Iceberg on Kubernetes 打造新一代雲原生資料湖
The AI method put forward by China has more and more influence. Tianda et al. Mined the development law of AI from a large number of literatures
【:: 是什么语法?】
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
【ElasticSearch搜索引擎】
解决 WPF 绑定集合后数据变动界面却不更新的问题
理解格式化原理
IPFs rudder filecoin landing at the same time, fil currency price broke a thousand
Swagger 3.0 brushes the screen every day. Does it really smell good?
What are Devops