I am trying to make a log reader , which will read the log ..and the user will input a search string .. i want to get the output in a excel file containing the whole line in which this string is found
try {
FileReader fis = null;
FileWriter fw;
BufferedReader in = new BufferedReader(
new FileReader(
"C:\\Users\\Arpit\\Downloads\\CodingCompetitionDocuments\\Sample.log"));
fw = new FileWriter("C:\\Users\\Arpit\\Documents\\demo3.xls");
fis = new FileReader(
"C:\\Users\\Arpit\\Downloads\\CodingCompetitionDocuments\\Sample.log");
char[] buf = new char[128];
/*
* while(true) { int n = fis.read(buf); if(n < 0) break; // end of
* file reached fw.write(buf, 0, n); }
*/
String line = "";
ArrayList arr = new ArrayList();
int linenum = 1;
while ((line = in.readLine()) != null) {
fw.write(linenum + "\t" + line);
arr.add(line);
fw.write("\n");
linenum++;
}
String findString = "doNotRefer";
int SizeString = findString.length();
int first = 0, two = 0;
String substr = "";
for (int i = 0; i < arr.size(); i++) {
String Line = arr.get(i).toString();
for (int j = 0; j < Line.length(); j++) {
if ((j + SizeString) > (Line.length())) {
break;
}
substr = Line.substring(j, j + SizeString);
// System.out.println(substr);
if ((substr.equals("doNotRefer")) == true) {
System.out.println(substr);
System.out.println("Find in Line" + (i + 1));
}
}
}
// System.setOut(new PrintStream(new BufferedOutputStream(new
// FileOutputStream("C:\\Users\\Arpit\\Documents\\demo2.txt"))));
fis.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}