[Java] 正则表达式 02 EmailSpider 抓邮件, CodeCounter 统计程序有效代码行数
来源:互联网 发布:js数组遍历下标 编辑:程序博客网 时间:2024/05/21 20:21
EmailSpider.java
import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.regex.Matcher;import java.util.regex.Pattern;public class EmailSpider { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new FileReader("D:\\share\\EmailHtm\\email.htm")); String line = ""; while((line=br.readLine()) != null) { parse(line); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static void parse(String line) { Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+"); Matcher m = p.matcher(line); while(m.find()) { System.out.println(m.group()); } }}
CodeCounter.java
import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;public class CodeCounter { static long normalLines = 0; static long commentLines = 0; static long whiteLines = 0; public static void main(String[] args) { File f = new File("D:\\share\\JavaProjects\\CodeCounter\\src"); File[] codeFiles = f.listFiles(); for(File child : codeFiles){ if(child.getName().matches(".*\\.java$")) { parse(child); } } /* * * */ System.out.println("normalLines:" + normalLines); System.out.println("commentLines:" + commentLines); System.out.println("whiteLines:" + whiteLines); } private static void parse(File f) { BufferedReader br = null; boolean comment = false; try { br = new BufferedReader(new FileReader(f)); String line = ""; while((line = br.readLine()) != null) { // readLine() 已经吃掉了后面的换行符号 line = line.trim(); if(line.matches("^[\\s&&[^\\n]]*$")) { whiteLines ++; } else if (line.startsWith("/*") && !line.endsWith("*/")) { commentLines ++; comment = true; } else if (line.startsWith("/*") && line.endsWith("*/")) { commentLines ++; } else if (true == comment) { commentLines ++; if(line.endsWith("*/")) { comment = false; } } else if (line.startsWith("//")) { commentLines ++; } else { normalLines ++; } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if(br != null) { try { br.close(); br = null; } catch (IOException e) { e.printStackTrace(); } } } }}
0 0
- [Java] 正则表达式 02 EmailSpider 抓邮件, CodeCounter 统计程序有效代码行数
- java 正则表达式2 通过正则表达式统计代码行数
- 统计*.Java文件代码行数——正则表达式
- 统计代码有效行数
- VS2013 用正则表达式统计代码行数
- VS用正则表达式统计代码行数
- CodeCounter代码统计
- 利用正则表达式统计某个某个文件夹下所有java文件的 空格行数、注释行数、和代码行数
- Java正则表达式(三)、代码量统计工具(统计java源文件中注释、代码、空白行数量)
- 正则表达式统计代码行数,注释行,空白行
- Visual Studio使用正则表达式快速统计总共代码行数
- java 统计程序项目下面所有Java类的个数和有效代码行数的递归算法
- 统计java代码行数
- Java统计代码行数
- JAVA统计代码行数
- java统计代码行数
- java代码行数统计
- java 统计代码行数
- Android 代码强制启动GPU渲染
- EntityFramework之领域驱动设计实践(二)
- C# winform下的富文本编辑器
- html <table>表数据转 Json 格式
- 我对linux内核链表实现中的部分函数的理解——第一节
- [Java] 正则表达式 02 EmailSpider 抓邮件, CodeCounter 统计程序有效代码行数
- 小强的HTML5移动开发之路(32)—— JavaScript回顾7
- 阿峰SEO-飘
- HTML5 canvas画图并保存成图片插件
- OCP认证流程详解
- 最后一课:日本如何输掉新互联网时代
- Spring框架学习【基础知识】
- 解决打开Excel时提示“您尝试打开的文件.xls的格式与文件扩展名指定的格式不一致
- 算法的重要性-The Importance of Algorithm()