I am reading a log file line by line using BufferedReader. If a line is match an exact pattern i also acquire previous lines. This line number is entered by user. For example pattern is "ERROR" and line number 3 so i will store ERROR line and previous 3 lines.
FileInputStream fInStream = new FileInputStream(fileBase);
br = new BufferedReader(new InputStreamReader(fInStream));
while ((line = br.readLine()) != null) {
if(line.contains("ERROR")){
//here, i should write previous 3 lines and then ERROR line
bw.write(line + "\r\n");
}
}
Any suggestions will be appreciated.