当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Novice guidance and event management system in game development
- PHP application docking justswap special development kit【 JustSwap.PHP ]
- 2020-09-09:裸写算法:两个线程轮流打印数字1-100。
- With this artifact, quickly say goodbye to spam messages
- Common syntax corresponding table of mongodb and SQL
- How to make characters move
- The legality of IPFs / filecoin: protecting personal privacy from disclosure
- What the hell is fastthreadlocal? The existence of ThreadLocal!!
- Filecoin has completed a major upgrade and achieved four major project progress!
- The native API of the future trend of the front end: web components
猜你喜欢
意外的元素..所需元素..
Zero basis to build a web search engine of its own
行为型模式之解释器模式
Description of phpshe SMS plug-in
行为型模式之备忘录模式
磁存储芯片STT-MRAM的特点
An article will introduce you to CSS3 background knowledge
Small program introduction to proficient (2): understand the four important files of small program development
ado.net和asp.net的关系
Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
随机推荐
Introduction to the development of small game cloud
Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
2020-08-20:GO语言中的协程与Python中的协程的区别?
Countdown | 2020 PostgreSQL Asia Conference - agenda arrangement of Chinese sub Forum
The Interpreter pattern of behavior pattern
EOS founder BM: what's the difference between UE, UBI and URI?
磁存储芯片STT-MRAM的特点
#JVM 类加载机制
ES6 learning notes (5): easy to understand ES6's built-in extension objects
迅为-iMX6ULL开发板上配置AP热点
This project allows you to quickly learn about a programming language in a few minutes
Helping financial technology innovation and development, atfx is at the forefront of the industry
2020-08-17:详细说下数据倾斜怎么解决?
Code generator plug-in and creator preform file analysis
Zhou Jie: database system of East China Normal University
2020-09-03:裸写算法:回形矩阵遍历。
STM32F030F4P6兼容灵动微MM32F031F4P6
Open source a set of minimalist front and rear end separation project scaffold
What grammar is it? ]
How much disk space does a new empty file take?