当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
- Code generator plug-in and creator preform file analysis
- A small goal in 2019 to become a blog expert of CSDN
- Zhou Jie: database system of East China Normal University
- 超高频RFID医疗血液管理系统应用
- 非易失性MRAM存储器应用于各级高速缓存
- ES中删除索引的mapping字段时应该考虑的点
- Junit测试出现 empty test suite
- Python 100 cases
- 意外的元素..所需元素..
猜你喜欢

ES中删除索引的mapping字段时应该考虑的点

Why is the LS command stuck when there are too many files?

Introduction to Huawei cloud micro certification examination

Detect certificate expiration script

STM32F030K6T6兼容替换灵动MM32F031K6T6

An article takes you to understand CSS gradient knowledge

磁存储芯片STT-MRAM的特点

Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios

2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?

How to start the hidden preferences in coda 2 on the terminal?
随机推荐
Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
How to make characters move
Those who have worked in China for six years and a million annual salary want to share these four points with you
STM32F030K6T6兼容替换灵动MM32F031K6T6
An article will introduce you to CSS3 background knowledge
2020-08-24:什么是小文件?很多小文件会有什么问题?很多小文件怎么解决?(大数据)
Erd-online free online database modeling tool
代码重构之法——方法重构分析
Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
STM32F030C6T6兼容替换MM32SPIN05PF
超高频RFID医疗血液管理系统应用
mongo 用户权限 登录指令
2020-08-30:裸写算法:二叉树两个节点的最近公共祖先。
Windows 10 蓝牙管理页面'添加蓝牙或其他设备'选项点击无响应的解决方案
The legality of IPFs / filecoin: protecting personal privacy from disclosure
What is the tensor in tensorflow?
2020-08-19:TCP是通过什么机制保障可靠性的?
Small program introduction to proficient (2): understand the four important files of small program development
How to manage the authority of database account?