Obtain valid email addresses of webpages in Java

Source: Internet
Author: User
Tags valid email address

// Obtain the valid email address of the webpage in Java --- by 77

 

 

 

Import java. AWT .*;
Import java. AWT. event .*;
Import java.net .*;
Import java. Io .*;
Import java. util .*;
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;
Public class solo7 {
Public static void main (string ARGs []) {
New win ();
}
}
Class win extends frame implements actionlistener, runnable {
Button button;
URL;
Textfield text;
Textarea area;
Byte B [] = new byte [118];
Thread thread;
Win (){
TEXT = new textfield (20 );
Area = new textarea (12, 12 );
Button = new button ("OK ");
Button. addactionlistener (this );
Thread = new thread (this );
Panel P = new Panel ();
P. Add (new label ("Enter URL :"));
P. Add (text );
P. Add (button );
Add (area, borderlayout. center );
Add (p, borderlayout. North );
Setbounds (60, 60, 360,300 );
Setvisible (true );
Validate ();
Addwindowlistener (New windowadapter (){
Public void windowclosing (windowevent e ){
System. Exit (0 );
}
});
}
Public void actionreceivmed (actionevent e ){
If (! (Thread. isalive ()))
Thread = new thread (this );
Try {
Thread. Start ();
}
Catch (exception ee ){
Text. settext ("reading" + URL );
}
}
Private Boolean isnameadressformat (string email ){
Boolean isexist = false;
Pattern P = pattern. Compile ("// W {1, }@// W {1 ,}

/56 // W {1 ,}");
Matcher M = P. matcher (email );
Boolean B = M. Matches ();
If (B ){
Isexist = true;
} Else {
Isexist = false;
}
Return isexist;
}

Public void run (){
Try {
Int n =-1;
Area. settext (null );
Url = new URL (text. gettext (). Trim ());
Inputstream in = URL. openstream ();
String S = "";
While (n = in. Read (B ))! =-1 ){
S + = new string (B, 0, N );
}
Stringtokenizer Fenxi = new stringtokenizer (S ,"

: = ,?!. : <> & () [] {} // "/'");
Int I = Fenxi. counttokens ();
Area. append ("Total" + I + "strings, such as valid email addresses

Below :");
While (Fenxi. hasmoretokens ()){
String STR = Fenxi. nexttoken ();
If (isnameadressformat (STR ))
Area. append (STR + "");
}
}
Catch (malformedurlexception E1 ){
Text. settext ("" + E1 );
Return;
}
Catch (ioexception E1 ){
Text. settext ("" + E1 );
Return;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.