当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- Building a new generation cloud native data lake with iceberg on kubernetes
- 快速排序为什么这么快?
- 【转发】查看lua中userdata的方法
- Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
- [C] (original) step by step teach you to customize the control element - 04, ProgressBar (progress bar)
- Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
- 【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
- Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
- An article will take you to understand SVG gradient knowledge
猜你喜欢
面试官: ShardingSphere 学一下吧
Introduction to the structure of PDF417 bar code system
What are the common problems of DTU connection
StickEngine-架构12-通信协议
What are the criteria for selecting a cluster server?
代码生成器插件与Creator预制体文件解析
It's time for your financial report to change to a more advanced style -- financial analysis cockpit
事务的本质和死锁的原理
PHP application docking justswap special development kit【 JustSwap.PHP ]
Git rebase is in trouble. What to do? Waiting line
随机推荐
StickEngine-架构12-通信协议
Tron smart wallet PHP development kit [zero TRX collection]
Basic principle and application of iptables
How to turn data into assets? Attracting data scientists
Diamond standard
Even liver three all night, jvm77 high frequency interview questions detailed analysis, this?
前端未來趨勢之原生API:Web Components
Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
python100例項
Use modelarts quickly, zero base white can also play AI!
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
面试官: ShardingSphere 学一下吧
事件监听问题
How to understand Python iterators and generators?
Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
What are manufacturing and new automation technologies?
美团内部讲座|周烜:华东师范大学的数据库系统研究
Pollard's Rho algorithm
【学习】接口测试用例编写和测试关注点
检测证书过期脚本