统计代码有效行数
来源:互联网 发布:警服照试穿软件 编辑:程序博客网 时间:2024/06/05 17:15
统计有效代码
import java.io.*;public class countUsefulLines {static long normalLines = 0; //文件总共行数static long commentLines = 0; //注释行static long whiteLines = 0; //空格行public static void main(String[] args) {File f = new File("C:/Users/UserName/Desktop/ed.txt");if(!f.exists()) {p("不存在该文件");System.exit(-1);}BufferedReader br = null;boolean comment;try {br = new BufferedReader(new FileReader(f));String line;comment = false;while((line = br.readLine()) != null) {normalLines ++; //只要非空就行数加1if(line.matches("^\\s*$"))whiteLines ++; //匹配空行加1else if(true == comment) {commentLines ++; //只要还在注释行则加1if(line.endsWith("*/"))comment = false; //退出注释行置为false}else if(line.startsWith("//"))commentLines ++; //注释行else if(line.startsWith("/*")) {commentLines ++;if(!line.endsWith("*/"))comment = true; //开始进入注释块}}} catch (IOException e) {e.printStackTrace();} finally {if(br != null) {try {br.close();br = null;} catch (IOException e) {e.printStackTrace();}}p("总共有" + normalLines + "行代码");p("总共有" + whiteLines + "行空行代码");p("总共有" + commentLines + "行注释行代码");p("有效代码行数:" + (normalLines-whiteLines-commentLines));}}static void p(Object o) {System.out.println(o);}}
阅读全文
0 0
- 统计代码有效行数
- Visual Studio统计有效代码行数
- Visual Studio统计有效代码行数
- Visual Studio统计有效代码行数
- Visual Studio统计有效代码行数
- Visual Studio统计有效代码行数
- Visual Studio统计有效代码行数
- [转]Visual Studio 统计有效代码行数
- 统计有效、空行、注解代码行数
- 简易统计Python有效代码行数
- 统计有效行数
- 统计C#项目有效代码行数的实现过程
- C++统计代码注释行数 & 有效代码行数 & 代码注释公共行 & 函数个数
- 统计代码行数代码
- 代码行数统计类
- 代码行数统计器
- 统计代码行数源码
- 统计代码行数
- Struts2 实现多文件上传
- 448. Find All Numbers Disappeared in an Array(java)
- Python学习笔记——动态添加属性与方法
- 对象说睡前要敲几行代码
- lua ...的使用
- 统计代码有效行数
- 省市联动的JSON格式数据
- 面试总结-成长之路
- 总结div水平居中的方法
- MapReduce实现寻找共同好友
- hdu 3999 The order of a Tree
- 数字统计(NOIP2010)
- Ubuntu 16.04 ssh安装--个人心得
- sparkSQL架构分析