当前位置:网站首页>Count the number of project code lines
Count the number of project code lines
2020-11-06 21:40:00 【Architects who can drive】
package com.travelsky.falcon.controller.testPackage.countCode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* Statistics under the specified directory java The number of lines in the file
* @author wdm
* @date
*/
public class CountFileRow {
private static int total = 0;
private static int fileNum = 1;
/*
* Count the number of lines in a single file
*/
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){
// Remove the space
String trimStr = line.trim();
// If the /,* start , Just skip the loop
if(trimStr.startsWith("/") || trimStr.startsWith("*") || trimStr.length()<=0){
continue;
}else{
total++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* Traverse all the files in the specified directory
*/
public static void fileTraversal(File directory){
File[] file = directory.listFiles();
for(int i=0; i<file.length; i++){
if(file[i].isDirectory()){ // If this object is a directory , Just recursion
fileTraversal(file[i]);
}else{
if(file[i].getName().endsWith(".java")){// Judge whether .java ending
System.out.println(" The first "+(++fileNum)+" File :\t"+file[i]);
singleFile(file[i]);// Count the number of lines in a single file
}
}
}
}
public static void main(String[] args) {
File dir = new File("D:\\workspace\\trunk");
fileTraversal(dir);
System.out.println(" common "+total+" Line code ");
}
}
版权声明
本文为[Architects who can drive]所创,转载请带上原文链接,感谢
边栏推荐
- 实用工具类函数(持续更新)
- The essence of transaction and the principle of deadlock
- C language I blog assignment 03
- Cloudquery v1.2.0 release
- Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)
- 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
- The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
- A small goal in 2019 to become a blog expert of CSDN
- The method of realizing high SLO on large scale kubernetes cluster
- Exclusive interview of guests at | 2020 PostgreSQL Asia Conference: Wang Tao
猜你喜欢
mongo 用户权限 登录指令
Zero basis to build a web search engine of its own
window系统 本机查找端口号占用方法
谷歌浏览器实现视频播放加速功能
Road to simple HTML + JS to achieve the most simple game Tetris
磁存储芯片STT-MRAM的特点
ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
What are the highlights of Huawei mate 40 series with HMS?
An article will take you to understand SVG gradient knowledge
An article will introduce you to HTML tables and their main attributes
随机推荐
The legality of IPFs / filecoin: protecting personal privacy from disclosure
ES中删除索引的mapping字段时应该考虑的点
To Lianyun analysis: why is IPFs / filecoin mining so difficult?
To solve the problem that the data interface is not updated after WPF binding set
How does cglib implement multiple agents?
Using an example to understand the underlying processing mechanism of JS function
ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
ES6 learning notes (2): teach you to play with class inheritance and class objects
Git rebase is in trouble. What to do? Waiting line
ES6 learning notes (3): teach you to use js object-oriented thinking to realize the function of adding, deleting, modifying and checking tab column
Why is the LS command stuck when there are too many files?
Junit测试出现 empty test suite
Code generator plug-in and creator preform file analysis
A concise tutorial for Nacos, ribbon and feign
How much disk space does a file of 1 byte actually occupy
Novice guidance and event management system in game development
消防器材RFID固定资产管理系统
2020-08-30:裸写算法:二叉树两个节点的最近公共祖先。
C and C / C + + mixed programming series 5 - GC collaboration of memory management
Unity performance optimization