当前位置:网站首页>统计项目代码行数
统计项目代码行数
2020-11-06 21:40:00 【会开车的架构师】
package com.travelsky.falcon.controller.testPackage.countCode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* 统计指定目录下java文件的行数
* @author wdm
* @date
*/
public class CountFileRow {
private static int total = 0;
private static int fileNum = 1;
/*
* 统计单个文件的行数
*/
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){
//去除空格
String trimStr = line.trim();
//如果以/,*开头,就跳过该次循环
if(trimStr.startsWith("/") || trimStr.startsWith("*") || trimStr.length()<=0){
continue;
}else{
total++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* 遍历指定目录下所有的文件
*/
public static void fileTraversal(File directory){
File[] file = directory.listFiles();
for(int i=0; i<file.length; i++){
if(file[i].isDirectory()){ //此对象如果是目录,就递归
fileTraversal(file[i]);
}else{
if(file[i].getName().endsWith(".java")){//判断是否以.java结尾
System.out.println("第"+(++fileNum)+"个文件:\t"+file[i]);
singleFile(file[i]);//统计单个文件的行数
}
}
}
}
public static void main(String[] args) {
File dir = new File("D:\\workspace\\trunk");
fileTraversal(dir);
System.out.println("共"+total+"行代码");
}
}
版权声明
本文为[会开车的架构师]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4629483/blog/4529704
边栏推荐
- Use modelarts quickly, zero base white can also play AI!
- Isn't data product just a report? absolutely wrong! There are university questions in this category
- Outsourcing is really difficult. As an outsourcer, I can't help sighing.
- image operating system windows cannot be used on this platform
- 华为Mate 40 系列搭载HMS有什么亮点?
- How does filecoin's economic model and future value support the price of fil currency breaking through thousands
- html+vue.js 實現分頁可相容IE
- Details of dapr implementing distributed stateful service
- Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
- 2020年第四届中国 BIM (数字建造)经理高峰论坛即将在杭举办
猜你喜欢
代码生成器插件与Creator预制体文件解析
Unity性能优化整理
How about small and medium-sized enterprises choose shared office?
Description of phpshe SMS plug-in
如何对数据库账号权限进行精细化管理?
The importance of big data application is reflected in all aspects
2020年数据库技术大会助力技术提升
事件监听问题
Use modelarts quickly, zero base white can also play AI!
检测证书过期脚本
随机推荐
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
[efficiency optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
Summary of front-end performance optimization that every front-end engineer should understand:
华为云微认证考试简介
Introduction to the structure of PDF417 bar code system
华为Mate 40 系列搭载HMS有什么亮点?
新建一个空文件占用多少磁盘空间?
How about small and medium-sized enterprises choose shared office?
PHP application docking justswap special development kit【 JustSwap.PHP ]
Gather in Beijing! The countdown to openi 2020
How to hide part of barcode text in barcode generation software
Custom function form of pychar shortcut key
Building a new generation cloud native data lake with iceberg on kubernetes
GitHub: the foundation of the front end
Shh! Is this really good for asynchronous events?
【字节跳动 秋招岗位开放啦】Ohayoo!放学别走,我想约你做游戏!!!
消息队列(MessageQueue)-分析
事件监听问题
html+vue.js 實現分頁可相容IE
事务的隔离级别与所带来的问题