java - finding an email in a text file and sorting the email information -


this question has answer here:

i have text file supposedly this

i hakan. email address hakan@cs.uh.edu, , name? hi name tarikul , favorite email address tarikul2000@uh.edu

im supposed create program locate emails in file store username,domaian, subdomain , extension rewrite them int text file.

import java.io.* ; import java.io.filenotfoundexception; import java.util.scanner; import java.io.printwriter; import java.io.fileoutputstream;  public class try {     public static void main(string[] args) {         email [] storage;// email class made store data         try {             scanner input= new scanner("inputemails.txt");             printwriter output= new printwriter("outputemails.txt");              }           catch (filenotfoundexception e) {             system.out.print("file not found");             system.exit(0);}         int i=0;         while(input.hasnextline()){             if(input.contains("@"));             {                 storage[i]=             }         }       }  } 

this have far , not how find email in text file?

also thought better if added actual instructions assignment, im not asking entire progam jus how separate data need find

  1. connect external input file. name of input file inputemails.txt, , therefore please don’t ask file name in program.
  2. detect email addresses in file.
  3. if email not have sub-domain, please create email object email.
  4. if email has sub-domain, please create universityemail object email.
  5. please store emails in same (one single) array list.
  6. after copy emails file array list, please ask user type of emails included in output file. if user enters 0, please write emails not have sub-domain in array list. please note output file must start number indicating number of emails in file. if user enters number between 1-7, please write emails specific department in output file. please note output file must start number indicating number of emails in file. user can enter 1 integer number 0 8

and subdomains talking are

1 art 2 chee 3 chem 4 coe 5 cs 6 egr 7 polsci

public static void fillemailshashset(string line,hashset<string> container){          pattern p = pattern.compile("([\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[a-za-z]{2,4})");         matcher m = p.matcher(line);          while(m.find()) {             container.add(m.group(1));         }      } 

you can find example of reading file here: https://stackoverflow.com/a/22074145/3315914

edit:

example input/output:

public static void emails() {         hashset<string> hs = new hashset<>();         filereader file = null;         try {             file = new filereader(new file("emails.txt"));         } catch (filenotfoundexception e1) {             system.err.println("file emails.txt not found!");             e1.printstacktrace();         }         bufferedreader br = new bufferedreader(file);         string line;         try {             while ((line = br.readline()) != null) {                 fillemailshashset(line, hs);             }          } catch (ioexception e) {             system.err.println("error when reading");             e.printstacktrace();         } {             if (br != null) {                 try {                     br.close();                 } catch (ioexception e) {                     system.err.println("unexpected error");                     e.printstacktrace();                 }             }         }         (string string : hs) {             system.out.println(string);         }     } 

input file contents:

dolor ac egestas purus thebumpy@whatever.com vestibulum justo. magna vulputate morbi theblue@whatever.com thejudicious@whatever.com nulla nec dui. adipiscing in theopen@whatever.com thefascinated@whatever.com sapien urna mi theharmonious@whatever.com vitae aliquam in eget pellentesque thephysical@whatever.com tellus. non sollicitudin faucibus et mi justo, sit nibh dapibus potenti. venenatis venenatis, molestie sed proin fermentum elementum. sed ut velit venenatis thedidactic@whatever.com dignissim consequat condimentum, porttitor lorem nibh felis, ullamcorper eros. ut diam vel ipsum nisi luctus. ultrices sem amet non aliquam aliquet lobortis mauris vestibulum est purus dignissim etiam cras in eget, sed pellentesque, thephobic@whatever.com eu amet, mauris magna euismod, odio semper lorem, potenti. dui tellus. thedetailed@whatever.com ut ipsum mi non suspendisse tempus cursus ac nec theminiature@whatever.com semper. ac, quis suscipit posuere, posuere suspendisse donec tristique sagittis  vel vitae urna aliquam vehicula sit condimentum. mi risus mollis rutrum varius. nec elit. nulla fusce thekaput@whatever.com sagittis dictum nunc, eget in theamusedgamer@gmail.com venenatis consectetur ultricies. interdum fermentum. ante thejolly@whatever.com eros quam. nec theelectric@whatever.com blandit. massa. molestie ac, thehistorical@whatever.com purus, ligula fringilla imperdiet lorem neque. et blandit tortor. enim sed, magna. 

output:

thephysical@whatever.com thehistorical@whatever.com theamusedgamer@gmail.com theblue@whatever.com thekaput@whatever.com theminiature@whatever.com thefascinated@whatever.com thephobic@whatever.com thebumpy@whatever.com thedetailed@whatever.com theharmonious@whatever.com thejudicious@whatever.com theelectric@whatever.com thejolly@whatever.com theopen@whatever.com thedidactic@whatever.com 

edit:

if want in form of array:

string[] array=hs.toarray(new string[hs.size()]); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -