当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- nacos、ribbon和feign的簡明教程
- 如何对数据库账号权限进行精细化管理?
- What knowledge do Python automated testing learn?
- From overseas to China, rancher wants to do research on container cloud market
- Building a new generation cloud native data lake with iceberg on kubernetes
- JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
- How to play sortable JS vuedraggable to realize nested drag function of forms
- 行为型模式之解释器模式
- Diamond standard
- Elasticsearch Part 6: aggregate statistical query
猜你喜欢

2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办

【:: 是什么语法?】

Description of phpshe SMS plug-in

01. SSH Remote terminal and websocket of go language

嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛

Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
![Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]](/img/14/ede1ffa7811dbc2a5b15b9a7b17a5e.jpg)
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]

Shh! Is this really good for asynchronous events?

What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online

From overseas to China, rancher wants to do research on container cloud market
随机推荐
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
[efficiency optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
Introduction to the structure of PDF417 bar code system
Asp.Net Core learning notes: Introduction
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
electron 實現檔案下載管理器
大道至简 html + js 实现最朴实的小游戏俄罗斯方块
ES6 learning notes (5): easy to understand ES6's built-in extension objects
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
How about small and medium-sized enterprises choose shared office?
What are the criteria for selecting a cluster server?
【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
Cglib 如何实现多重代理?
Analysis of query intention recognition
Basic usage of GDB debugging
What if the front end doesn't use spa? - Hacker News
【学习】接口测试用例编写和测试关注点
hdu3974 Assign the task線段樹 dfs序