当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Why is the LS command stuck when there are too many files?
- ado.net and asp.net The relationship between
- How much disk space does a file of 1 byte actually occupy
- An article takes you to understand CSS gradient knowledge
- image operating system windows cannot be used on this platform
- 上海巨微专用蓝牙广播芯片
- mongo 用户权限 登录指令
- Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election
- Description of phpshe SMS plug-in
- 行为型模式之备忘录模式
猜你喜欢

大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术

What is the tensor in tensorflow?

Using an example to understand the underlying processing mechanism of JS function

Summary of front-end performance optimization that every front-end engineer should understand:

Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election

【涂鸦物联网足迹】涂鸦云平台全景介绍

2020-09-09:裸写算法:两个线程轮流打印数字1-100。

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

git远程库回退指定版本

window系统 本机查找端口号占用方法
随机推荐
上海巨微专用蓝牙广播芯片
MRAM高速缓存的组成
2020-08-14:数据任务的执行引擎用的哪些?
What kind of music do you need to make for a complete game?
The role of theme music in games
ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
What are the highlights of Huawei mate 40 series with HMS?
Why is the LS command stuck when there are too many files?
意外的元素..所需元素..
Python basic variable type -- list analysis
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
Summary of front-end performance optimization that every front-end engineer should understand:
Code generator plug-in and creator preform file analysis
Why is quicksort so fast?
Hdu3974 assign the task segment tree DFS order
打工人好物——磨炼钢铁意志就要这样高效的电脑
Pn8162 20W PD fast charging chip, PD fast charging charger scheme
How to start the hidden preferences in coda 2 on the terminal?
An article will introduce you to HTML tables and their main attributes
Countdown | 2020 PostgreSQL Asia Conference - agenda arrangement of Chinese sub Forum