直接放在src/test/java包内运行

/**
* 代码行数统计
* @author ThinkGem
* @version 2014-7-22
*/
public class CodeCounter { public static void main(String[] args) {
//获取当前类的资源文件路径,即../../target/test-classes/
String file = CodeCounter.class.getResource("/").getFile();
// System.out.println(file);
//path=D:/Source_Code/koudaimini/src/
//设置统计根路径为src
// String path = file.replace("target/test-classes", "src");
String path = "D:\\Source_Code\\zbg\\modules\\zbg-api\\src"; ArrayList<File> al = CodeCounter.getFile(new File(path));
for (File f : al) {
if (f.getName().matches(".*\\.java$")){ // 匹配java格式的文件
CodeCounter.count(f);
System.out.println(f);
}
}
System.out.println("统计文件:" + CodeCounter.files);
System.out.println("代码行数:" + CodeCounter.codeLines);
System.out.println("注释行数:" + CodeCounter.commentLines);
System.out.println("空白行数:" + CodeCounter.blankLines);
}
static long files = 0;
static long codeLines = 0;
static long commentLines = 0;
static long blankLines = 0;
static ArrayList<File> fileArray = new ArrayList<File>(); /**
* 获得目录下的文件和子目录下的文件
* @param f
* @return
*/
public static ArrayList<File> getFile(File f) {
File[] ff = f.listFiles();
for (File child : ff) {
if (child.isDirectory()) {
CodeCounter.getFile(child);
} else {
CodeCounter.fileArray.add(child);
}
}
return CodeCounter.fileArray; } /**
* 统计方法
* @param f
*/
private static void count(File f) {
BufferedReader br = null;
boolean flag = false;
try {
br = new BufferedReader(new FileReader(f));
String line = "";
while ((line = br.readLine()) != null) {
line = line.trim(); // 除去注释前的空格
if (line.matches("^[ ]*$")) { // 匹配空行
CodeCounter.blankLines++;
} else if (line.startsWith("//")) {
CodeCounter.commentLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
CodeCounter.commentLines++;
flag = true;
} else if (line.startsWith("/*") && line.endsWith("*/")) {
CodeCounter.commentLines++;
} else if (flag == true) {
CodeCounter.commentLines++;
if (line.endsWith("*/")) {
flag = false;
}
} else {
CodeCounter.codeLines++;
}
}
CodeCounter.files++;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

类似结果

D:/。。/koudaimini/src/
统计文件:46
代码行数:2798
注释行数:814
空白行数:652

javaWeb代码工程统计的更多相关文章

  1. [statsvn]-svn代码量统计

    用statasvn进行代码量统计的时候,第一步需要获取到项目的日志,但是我本机的svn1.4没有安装命令行,重新运行1.4的安装包也没有命令行的选项... 那就升级到最新的svn1.8好了,下载最新的 ...

  2. 如何创建 SVN 服务器,并搭建自己的 SVN 仓库 如何将代码工程添加到VisualSVN Server里面管理

    如何创建 SVN 服务器,并搭建自己的 SVN 仓库,附链接: https://jingyan.baidu.com/article/6b97984dca0d9c1ca3b0bf40.html 如何将代 ...

  3. 【转】Git 代码行统计命令集

    查看git上个人代码量 git log --author="username" --pretty=tformat: --numstat | awk '{ add += $1; su ...

  4. IDEA 代码量统计(Statistic)

    IDEA 代码量统计(Statistic) 1.1 前言 项目到了一定阶段,都会想要看看项目的代码量情况,这里主要使用插件Statistic进行代码统计查看. 1.2 安装插件步骤 找到插件市场入口并 ...

  5. “代码量统计脚本”

    概述 本文从一段统计C/C++程序脚本入手,记录shell脚本常用和重要的知识点. 代码量统计程序 文件名称,count_code_line.sh 12345678910111213141516171 ...

  6. 代码图形统计工具git_stats web

    目录 一.简介 二.安装ruby 三.配置git_stats 四.通过nginx把网页展示出来 一.简介 仓库代码统计工具之一,可以按git提交人.提交次数.修改文件数.代码行数.注释量在时间维度上进 ...

  7. mac OS X下git代码行统计命令

    1.统计某人的代码提交量,包括增加,删除 git log --author=-- --until=-- --pretty=tformat: --numstat | awk '{ add += $1 ; ...

  8. 【转】Git代码行统计命令集

    http://blog.csdn.NET/dwarven/article/details/46550117 http://blog.csdn.net/hshl1214/article/details/ ...

  9. iOS纯代码工程手动快速适配

    首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...

随机推荐

  1. 2.Redis五种数据结构

    2.Redis五种数据结构2.1 预备2.1.1 全局命令2.1.2 数据结构和内部编码2.1.3 单线程架构2.2 字符串2.2.1 命令2.2.2 内部编码2.2.3 典型使用场景2.3 哈希2. ...

  2. iDoc「文档」功能强势升级!一键分享,即刻预览!(201903-1版本更新)

    小摹很想知道小伙伴们在面对众多杂乱的文档时,都是如何管理起来的呢?iDoc的「文档」功能,很多小伙伴还没有用起来,甚至都没有注意到iDoc还有这样一个功能.今天小摹就给大家介绍一下iDoc的「文档」功 ...

  3. solr7.7.0搜索引擎使用(四)(搜索语法)

    solr搜索语法 参数defType   指定用于处理查询语句(参数q的内容)的查询解析器,eg:defType=lucenesort    指定响应的排序方式:升序asc或降序desc.同时需要指定 ...

  4. 【Mybatis】MyBatis快速入门(一)

    Mybatis简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可 ...

  5. shell脚本学习-执行

    跟着RUNOOB网站的教程学习的笔记 Shell与Shell脚本 Shell是用户与Linux系统的桥梁.它既是一种命令语言,也是一种程序设计语言. Shell脚本是一种Shell编写的脚本程序,其实 ...

  6. 配置微信jssdk自定义分享

    前段时间做这个功能的时候遇到这个问题,之前的话是微信自动抓取界面第一张图,现在微信更新api,必须自行配置,接入jssdk,才能实现该功能. 详细可以查看微信的jssdk文档 微信官方开发者文档    ...

  7. 2019swpuj2ee作业一:C/S,B/S的应用的区别

    1.硬件环境不同: C/S 一般建立在专用的网络上, 小范围里的网络环境, 局域网之间再通过专门服务器提供连接和数据交换服务.B/S 建立在广域网之上的, 不必是专门的网络硬件环境,例与电话上网,  ...

  8. Maths | 二次型求偏导

  9. 准备在electron上用vue,结果卡在了sqlite3

    vue.js看书有一段时间了,也准备动手做一个electron的程序.目录似乎有两种方式搭建方式 一种是使用vue.cli构建工具,就是所谓的脚手架,分别安装vue和electron https:// ...

  10. Pattern Design - Strategy Pattern

    If you can disassemble code  and  you want to apply one method of an object in another object that t ...