当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Take you to learn the new methods in Es5
- Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
- Python 100 cases
- Pn8162 20W PD fast charging chip, PD fast charging charger scheme
- An article will take you to understand CSS alignment
- ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
- 预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
- Flink's datasource Trilogy: direct API
- EOS founder BM: what's the difference between UE, UBI and URI?
- The role of theme music in games
猜你喜欢
随机推荐
Zhou Jie: database system of East China Normal University
PHP application docking justswap special development kit【 JustSwap.PHP ]
Qt音视频开发46-视频传输UDP版
ado.net and asp.net The relationship between
ado.net和asp.net的关系
迅为iMX6开发板-设备树内核-menuconfig的使用
ES6 learning notes (5): easy to understand ES6's built-in extension objects
实用工具类函数(持续更新)
[forward] how to view UserData in Lua
Take you to learn the new methods in Es5
Unexpected element.. required element
Introduction to the development of small game cloud
STM32F030F4P6兼容灵动微MM32F031F4P6
image operating system windows cannot be used on this platform
Flink's datasource Trilogy: direct API
打工人好物——磨炼钢铁意志就要这样高效的电脑
How to make characters move
html+ vue.js Implementing paging compatible IE
The native API of the future trend of the front end: web components
An article takes you to understand CSS3 picture border
