当前位置:网站首页>统计项目代码行数
统计项目代码行数
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
边栏推荐
- Pn8162 20W PD fast charging chip, PD fast charging charger scheme
- C + + and C + + programmers are about to be eliminated from the market
- Ronglian completed US $125 million f round financing
- [efficiency optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
- hdu3974 Assign the task線段樹 dfs序
- 【自学unity2d传奇游戏开发】地图编辑器
- 【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
- WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
- What is the purchasing supplier system? Solution of purchasing supplier management platform
- Helping financial technology innovation and development, atfx is at the forefront of the industry
猜你喜欢
How to play sortable JS vuedraggable to realize nested drag function of forms
An article will take you to understand CSS3 fillet knowledge
消息队列(MessageQueue)-分析
StickEngine-架构11-消息队列(MessageQueue)
EOS founder BM: what's the difference between UE, UBI and URI?
解决 WPF 绑定集合后数据变动界面却不更新的问题
Helping financial technology innovation and development, atfx is at the forefront of the industry
C + + and C + + programmers are about to be eliminated from the market
Ronglian completed US $125 million f round financing
游戏主题音乐对游戏的作用
随机推荐
What are Devops
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
【转发】查看lua中userdata的方法
消息队列(MessageQueue)-分析
It's easy to operate. ThreadLocal can also be used as a cache
2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办
Use modelarts quickly, zero base white can also play AI!
Interpretation of Cocos creator source code: engine start and main loop
Take you to learn the new methods in Es5
What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online
Description of phpshe SMS plug-in
DRF JWT authentication module and self customization
Behind the first lane level navigation in the industry
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
In depth to uncover the bottom layer of garbage collection, this time let you understand her thoroughly
Analysis of ThreadLocal principle
一部完整的游戏,需要制作哪些音乐?
ES6 learning notes (5): easy to understand ES6's built-in extension objects
How to hide part of barcode text in barcode generation software
What is the purchasing supplier system? Solution of purchasing supplier management platform