当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- MongoDB与SQL常用语法对应表
- Get twice the result with half the effort: automation without cabinet
- How about small and medium-sized enterprises choose shared office?
- Small program introduction to proficient (2): understand the four important files of small program development
- 每个大火的“线上狼人杀”平台,都离不开这个新功能
- It's easy to operate. ThreadLocal can also be used as a cache
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
- 华为Mate 40 系列搭载HMS有什么亮点?
- 快速排序为什么这么快?
- hdu3974 Assign the task線段樹 dfs序
猜你喜欢

Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?

Description of phpshe SMS plug-in

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

JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m

Multi robot market share solution

It's easy to operate. ThreadLocal can also be used as a cache

华为云微认证考试简介

消息队列(MessageQueue)-分析

Cglib 如何实现多重代理?

小游戏云开发入门
随机推荐
What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online
Digital city responds to relevant national policies and vigorously develops the construction of digital twin platform
代码生成器插件与Creator预制体文件解析
EOS founder BM: what's the difference between UE, UBI and URI?
StickEngine-架构12-通信协议
How to demote domain controllers and later in Windows Server 2012
Behind the first lane level navigation in the industry
Jmeter——ForEach Controller&Loop Controller
JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
Pollard's Rho algorithm
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
美团内部讲座|周烜:华东师范大学的数据库系统研究
新建一个空文件占用多少磁盘空间?
What course of artificial intelligence? Will it replace human work?
python100例項
C# 调用SendMessage刷新任务栏图标(强制结束时图标未消失)
【自学unity2d传奇游戏开发】地图编辑器
面试官: ShardingSphere 学一下吧
每个大火的“线上狼人杀”平台,都离不开这个新功能
Use modelarts quickly, zero base white can also play AI!