java - How to skip a header after regex match and read next line using BufferReader -
i have stream continue print rows follows:
11:19:54 cpu %user %nice %system %iowait %steal %idle 11:19:55 0.00 0.00 1.00 0.00 0.00 99.00 average: 0.00 0.00 1.00 0.00 0.00 99.00 11:19:55 cpu %user %nice %system %iowait %steal %idle 11:19:56 0.00 0.00 1.00 0.00 0.00 99.00 average: 0.00 0.00 1.00 0.00 0.00 99.00
....so on
java code is:
public final static string regex_starts_with_time = "[0-9]{2}:[0-9]{2}:[0-9]{2}\\s+[a-z]{2}\\s"; public final static string regex = regex_starts_with_time + "cpu\\s+%usr\\s"; string line; try { inputstream = process.getinputstream(); bufferedreader br = new bufferedreader(new inputstreamreader(is)); while ((line = br.readline()) != null) { line.matches(regex); //here want read next line skipping header. } br.close(); } catch (ioexception e) { ...... }
i want skip header , read next line.
you can use string#contains("cpu")
check if line contains sub-string. if does, (then header,) call continue
in loop.
side note : can achieved using indexof()
well. don't see reason use regex here .
Comments
Post a Comment