当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- 【学习】接口测试用例编写和测试关注点
- Use modelarts quickly, zero base white can also play AI!
- (1) ASP.NET Introduction to core3.1 Ocelot
- 一部完整的游戏,需要制作哪些音乐?
- 面试官: ShardingSphere 学一下吧
- Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
- 游戏主题音乐对游戏的作用
- PHP application docking justswap special development kit【 JustSwap.PHP ]
- What is alicloud's experience of sweeping goods for 100 yuan?
- ado.net和asp.net的关系
猜你喜欢
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
Summary of front-end performance optimization that every front-end engineer should understand:
华为云微认证考试简介
事务的隔离级别与所带来的问题
Diamond standard
【ElasticSearch搜索引擎】
Ronglian completed US $125 million f round financing
01. SSH Remote terminal and websocket of go language
行为型模式之解释器模式
随机推荐
What is alicloud's experience of sweeping goods for 100 yuan?
Diamond standard
Network programming NiO: Bio and NiO
(1) ASP.NET Introduction to core3.1 Ocelot
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
Building a new generation cloud native data lake with iceberg on kubernetes
代码生成器插件与Creator预制体文件解析
What is the purchasing supplier system? Solution of purchasing supplier management platform
行为型模式之解释器模式
文件过多时ls命令为什么会卡住?
意外的元素..所需元素..
Description of phpshe SMS plug-in
MongoDB与SQL常用语法对应表
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛
An article will take you to understand SVG gradient knowledge
Digital city responds to relevant national policies and vigorously develops the construction of digital twin platform
Git rebase is in trouble. What to do? Waiting line
hdu3974 Assign the task線段樹 dfs序
游戏主题音乐对游戏的作用
A small goal in 2019 to become a blog expert of CSDN