One: Crawl the email address in the webpage
Using regular expressions to match text in a Web page
Copy Code code as follows:
[\\w[.-]]+@[\\w[.-]]+\\. [\\w]+
Split the page content to extract
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 Bufferedread ER (new FileReader ("c:\\emailspider.html"));
String line = "";
while ((Line=br.readline ())!= null) {
parse (line);
}
catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
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 ());
}
}}
Print results:
867124664@qq.com
260678675@QQ.com
806208721@qq.com
Hr_1985@163.com
32575987@qq.com
Qingchen0501@126.com
Yingyihanxin@foxmail.com
1170382650@qq.com
1170382650@qq.com
Yingyihanxin@foxmail.com
Qingchen0501@126.com
32575987@qq.com
Hr_1985@163.com
Now you find so many email addresses, with the knowledge of JavaMail, you can send mass spam, hehe!!!
Two: Code statistics
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;//Normal code line static long Commentlines = 0;//Comment Line static long Whitel Ines = 0;//blank line public static void main (string[] args) {//Find a folder in which there is no folder, no write recursive processing files in the same folder file F = new
File ("E:\\workspaces\\eclipse\\application\\javamailtest\\src\\com\\java\\mail");
file[] Codefiles = F.listfiles ();
for (file child:codefiles) {///Statistics only Java file 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;
Indicates whether to start Boolean comment = False for the comment;
try {br = new BufferedReader (new FileReader (f)); String Line = "";
while (line = Br.readline ())!= null) {//Remove the blank line = Line.trim () that may appear before the annotation character/*; Empty line because ReadLine () has removed the string, the newline character \ n//So is not "^[\\s&&[^\\n]]*\\n$" if (line.matches) ("^[\\s&&[
^\\n]]*$ ")) {whitelines + +;
else if (Line.startswith ("*") &&!line.endswith ("* *")) {//statistic multiline/*****/Commentlines + +;
Comment = true;
else if (Line.startswith ("*") && line.endswith ("* *")) {//statistic row/**/Commentlines + +;
else if (true = = comment) {//Statistics */commentlines + +;
if (Line.endswith ("* *")) {comment = false;
} else if (Line.startswith ("//)") {commentlines + +;
else {normallines + +;
A catch (FileNotFoundException e) {e.printstacktrace ());
catch (IOException e) {e.printstacktrace (); finally {if (BR != null) {try {br.close ();
br = NULL;
catch (IOException e) {e.printstacktrace (); }
}
}
}
}
The above content is this article to share Java in the regular expression of the use, I hope you like.