当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- STM32F030C6T6兼容替换MM32SPIN05PF
- How to start the hidden preferences in coda 2 on the terminal?
- Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
- 2020-08-30:裸写算法:二叉树两个节点的最近公共祖先。
- 2020-08-15:什么情况下数据任务需要优化?
- Python basic variable type -- list analysis
- Description of phpshe SMS plug-in
- vue3 新特性
- 代码重构之法——方法重构分析
- Summary of common SQL statements
猜你喜欢

list转换map(根据key来拆分list,相同key的value为一个list)

To teach you to easily understand the basic usage of Vue codemirror: mainly to achieve code editing, verification prompt, code formatting

意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……

Detect certificate expiration script

Markdown tricks

The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020

Zero basis to build a web search engine of its own

Interviewer: how about shardingsphere

Take you to learn the new methods in Es5
![PHP application docking justswap special development kit【 JustSwap.PHP ]](/img/3b/00bc81122d330c9d59909994e61027.jpg)
PHP application docking justswap special development kit【 JustSwap.PHP ]
随机推荐
The role of theme music in games
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
PHP application docking justswap special development kit【 JustSwap.PHP ]
Helping financial technology innovation and development, atfx is at the forefront of the industry
Summary of front-end performance optimization that every front-end engineer should understand:
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
What are the highlights of Huawei mate 40 series with HMS?
STM32F030C6T6兼容替换MM32SPIN05PF
[self taught unity2d legendary game development] map editor
Using iceberg on kubernetes to create a new generation of cloud original data Lake
Can you do it with only six characters?
CloudQuery V1.2.0 版本发布
es创建新的索引库并拷贝旧的索引库 实践亲测有效!
Filecoin has completed a major upgrade and achieved four major project progress!
Code generator plug-in and creator preform file analysis
2020-08-14:数据任务的执行引擎用的哪些?
2020-08-15:什么情况下数据任务需要优化?
An article will introduce you to HTML tables and their main attributes
An article will introduce you to CSS3 background knowledge