当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- A small goal in 2019 to become a blog expert of CSDN
- Zero basis to build a web search engine of its own
- What the hell is fastthreadlocal? The existence of ThreadLocal!!
- ES6 learning notes (4): easy to understand the new grammar of ES6
- Python basic variable type -- list analysis
- The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
- Nodejs中使用jsonwebtoken(JWT)生成token的场景使用
- 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
- 【涂鸦物联网足迹】涂鸦云平台全景介绍
- Zhou Jie: database system of East China Normal University
猜你喜欢
随机推荐
Python 100 cases
Countdown | 2020 PostgreSQL Asia Conference - agenda arrangement of Chinese sub Forum
[byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!
MRAM高速缓存的组成
How to make characters move
A concise tutorial for Nacos, ribbon and feign
Unity performance optimization
【涂鸦物联网足迹】物联网基础介绍篇
How to prepare for the system design interview
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
What grammar is it? ]
The isolation level of transaction and its problems
Zero basis to build a web search engine of its own
What is the meaning of sector sealing of filecoin mining machine since the main network of filecoin was put online
Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
What are the highlights of Huawei mate 40 series with HMS?
mongo 用户权限 登录指令
Exclusive interview with Alibaba cloud database for 2020 PostgreSQL Asia Conference: Zeng Wenjing
How does cglib implement multiple agents?
