1 ImportJava.io.BufferedReader;2 Importjava.io.FileNotFoundException;3 ImportJava.io.FileReader;4 Importjava.io.IOException;5 ImportJava.util.regex.Matcher;6 ImportJava.util.regex.Pattern;7 8 9 Public classEmailspider {Ten One Public Static voidMain (string[] args) { A Try { -BufferedReader br =NewBufferedReader (NewFileReader ("d:\\share\\courseware\\1043633.html")); -String line = ""; the while((Line=br.readline ())! =NULL) { - parse (line); - } -}Catch(FileNotFoundException e) { + //TODO auto-generated Catch block - e.printstacktrace (); +}Catch(IOException e) { A //TODO auto-generated Catch block at e.printstacktrace (); - } - } - - Private Static voidParse (String line) { -Pattern p = pattern.compile ("[\\w[.-]][email protected][\\w[.-]]+\\.[ \\w]+ "); inMatcher m =P.matcher (line); - while(M.find ()) { to System.out.println (M.group ()); + } - } the *}
Use regular expressions to extract email from a Web page