email - how to read lines start with string : Err from a text file and mail it to the recipients using JAVA -


  1. i have error log text file

  2. now read lines start text err ,and store in string array using java

  3. mail content of string array read

my piece of java code:

mimemessage message = new mimemessage(session);  string pathlogfile = "d:/logfile.log"; enumeration enumeration =     carparser1.logger.getrootlogger().getallappenders();             while ( enumeration.hasmoreelements() ){                appender appender = (appender) enumeration.nextelement();                if ( appender instanceof fileappender ){                   pathlogfile  = ((fileappender)appender).getfile();     //here path                   break;                }             }             stringbuffer sb = new stringbuffer();             fileinputstream fstream = new fileinputstream(pathlogfile);             bufferedreader br = new bufferedreader(new  inputstreamreader(fstream));              string singleline;             while ((singleline = br.readline()) != null) {               sb.append(singleline + "<br>");             }             br.close();             string alllines = sb.tostring();      message.setcontent(alllines, "text/html; charset=iso-8859-1");      transport.send(message);     system.out.println("email sent successfully...."); 

can me achieve this?

thank you

right reading logfile , sending in mail body. have add additional condition in loop filter out messages starting "err"

string singleline; while ((singleline = br.readline()) != null) {      if(singleline.startswith("err")) //filter condition           sb.append(singleline + "<br>"); } 

you can use contains("err") etc. depending on filter want.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -