当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- 【转发】查看lua中userdata的方法
- Contract trading system development | construction of smart contract trading platform
- Azure data factory (3) integrate azure Devops to realize CI / CD
- EOS founder BM: what's the difference between UE, UBI and URI?
- Building a new generation cloud native data lake with iceberg on kubernetes
- [efficiency optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
- 事务的本质和死锁的原理
- Introduction to Google software testing
- Who says cat can't do link tracking? Stand up for me
- C + + and C + + programmers are about to be eliminated from the market
猜你喜欢
Building a new generation cloud native data lake with iceberg on kubernetes
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
Share with Lianyun: is IPFs / filecoin worth investing in?
ado.net和asp.net的关系
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
每个大火的“线上狼人杀”平台,都离不开这个新功能
What are the common problems of DTU connection
游戏主题音乐对游戏的作用
Small program introduction to proficient (2): understand the four important files of small program development
随机推荐
What are PLC Analog input and digital input
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
2020年数据库技术大会助力技术提升
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
Uncle Bob: the software architecture is similar to a house. Object oriented is the structure of the house, and the water pipe is functional programming
開源一套極簡的前後端分離專案腳手架
Swagger 3.0 brushes the screen every day. Does it really smell good?
Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
It is really necessary to build a distributed ID generation service
hdu3974 Assign the task線段樹 dfs序
Shh! Is this really good for asynchronous events?
Analysis of serilog source code -- how to use it
Installing ns-3 on ubuntu18.04
Share with Lianyun: is IPFs / filecoin worth investing in?
Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
Details of dapr implementing distributed stateful service
es创建新的索引库并拷贝旧的索引库 实践亲测有效!
What course of artificial intelligence? Will it replace human work?