email - how to read lines start with string : Err from a text file and mail it to the recipients using JAVA -
i have error log text file
now read lines start text
err
,and store instring array
usingjava
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
Post a Comment