import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class LogFileProcessor {
// Function to get the count of lines in a log file
public static int getLineCount(String filePath) throws IOException {
int lineCount = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
while (reader.readLine() != null) {
lineCount++;
}
}
return lineCount;
}
public static void main(String[] args) {
String logFilePath = "path/to/your/logfile.log"; // Replace with your log file path
try {
int count = getLineCount(logFilePath);
System.out.println("Total lines in log file: " + count);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Not working as excepted ro read count ans ro get next lines
New contributor
Upkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1