用正则表达式统计java工作行,注释行,空白行
来源:互联网 发布:java开发app 编辑:程序博客网 时间:2024/04/27 09:44
static long blankline=0;
static long commentline=0;
static long workline=0;
public static void main(String[] args) throws IOException {
File file = new File("d:\\JAVA\\day12\\");
File[] listFiles = file.listFiles();
for (File file2 : listFiles) {
if(file2.getName().matches(".*\\.java$")){
Parser(file2);
}
}
System.out.println("空行:"+blankline);
System.out.println("注释行:"+commentline);
System.out.println("工作行:"+workline);
}
private static void Parser(File file2) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file2));
String line="";
boolean comment=false;
while((line=reader.readLine()) != null){
line=line.trim();
if(line.matches("^[\\s&&[^\\n]]*$")){
blankline++;
}else if(line.startsWith("/*") && !line.endsWith("*/")){
commentline++;
comment=true;
}else if(true==comment){
commentline++;
if(line.endsWith("*/")){
comment=false;
}
}else if(line.startsWith("//")){
commentline++;
}else if(line.startsWith("/*")&& line.endsWith("*/")){
commentline++;
}else{
workline++;
}
}
}
}
static long commentline=0;
static long workline=0;
public static void main(String[] args) throws IOException {
File file = new File("d:\\JAVA\\day12\\");
File[] listFiles = file.listFiles();
for (File file2 : listFiles) {
if(file2.getName().matches(".*\\.java$")){
Parser(file2);
}
}
System.out.println("空行:"+blankline);
System.out.println("注释行:"+commentline);
System.out.println("工作行:"+workline);
}
private static void Parser(File file2) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file2));
String line="";
boolean comment=false;
while((line=reader.readLine()) != null){
line=line.trim();
if(line.matches("^[\\s&&[^\\n]]*$")){
blankline++;
}else if(line.startsWith("/*") && !line.endsWith("*/")){
commentline++;
comment=true;
}else if(true==comment){
commentline++;
if(line.endsWith("*/")){
comment=false;
}
}else if(line.startsWith("//")){
commentline++;
}else if(line.startsWith("/*")&& line.endsWith("*/")){
commentline++;
}else{
workline++;
}
}
}
}
0 0
- 用正则表达式统计java工作行,注释行,空白行
- 正则表达式统计代码行数,注释行,空白行
- 正则表达式删除注释及空白行
- python 统计代码/注释/空白行 --- 0007
- Java正则表达式(三)、代码量统计工具(统计java源文件中注释、代码、空白行数量)
- editplus替换空白行的正则表达式
- 消除空白行^\s*\n,正则表达式
- java正则表达式例程 提取网页中的email 统计代码的空行 有效代码行 注释行
- 关于代码中空白、注释等字符的统计(正则表达式的使用)
- 利用正则表达式实现统计代码中的注释行、空行、以及代码行的数量。
- Python 正则表达式验证多行注释
- 正则表达式匹配行末后行首的空白符
- php里如何用正则表达式去除空白行
- ultraedit替换所有空白行 --正则表达式使用
- ultraedit替换所有空白行 --正则表达式使用
- C#用正则表达式替换多行注释
- 用正则表达式把多行连续空白替换成一个换行符
- 利用正则表达式统计代码中的(代码行数,注释行数,空白行数)利用正则表达式获取一个网页中所有的邮箱地址
- 解决:Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- 关于AngularJS学习整理---核心特性
- 从零开始学习Python在e站上下载蕾姆的本子
- 选中一行或多行的快捷键
- 测试apsx与aspx.cs 关系
- 用正则表达式统计java工作行,注释行,空白行
- python进行基本的图像处理
- mysql数据库数据类型
- bootstrap select2 动态改变值
- HDU 5923 Prediction (并查集)
- 怎样编辑pdf文件的重点部分
- Android-6步教你自定义View
- RBAC数据库的设计
- 463. Island Perimeter | 岛屿的周长