当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 统计项目代码行数
- 2020 database technology conference helps technology upgrade
- 2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
- Summary of front-end performance optimization that every front-end engineer should understand:
- vue3 新特性
- [elastic search engine]
- Share with Lianyun: is IPFs / filecoin worth investing in?
- mongo 用户权限 登录指令
- How much disk space does a file of 1 byte actually occupy
- Markdown tricks
猜你喜欢
预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
What the hell is fastthreadlocal? The existence of ThreadLocal!!
This project allows you to quickly learn about a programming language in a few minutes
Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
With this artifact, quickly say goodbye to spam messages
The native API of the future trend of the front end: web components
Helping financial technology innovation and development, atfx is at the forefront of the industry
How much disk space does a file of 1 byte actually occupy
Understanding formatting principles
A small goal in 2019 to become a blog expert of CSDN
随机推荐
Flink's datasource Trilogy: direct API
vue3 新特性
The role of theme music in games
意派Epub360丨你想要的H5模板都在这里,电子书、大转盘、红包雨、问卷调查……
ES6 learning notes (4): easy to understand the new grammar of ES6
The native API of the future trend of the front end: web components
Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election
代码重构之法——方法重构分析
Hdu3974 assign the task segment tree DFS order
【涂鸦物联网足迹】物联网基础介绍篇
DC-1 target
[forward] how to view UserData in Lua
行为型模式之备忘录模式
CloudQuery V1.2.0 版本发布
Exclusive interview of guests at | 2020 PostgreSQL Asia Conference: Wang Tao
Zero basis to build a web search engine of its own
Git rebase is in trouble. What to do? Waiting line
What the hell is fastthreadlocal? The existence of ThreadLocal!!
To Lianyun analysis: why is IPFs / filecoin mining so difficult?
Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey