I have an log file named abcd.log in my C: drive that I am reading it through a java program , I want to measure How much time the program had taken to completely read the log file please advise how to achieve this..!!
public class Readdemo {
public static void main(String[] args) {
File file = new File("C://abcd.log");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
System.out.println("Total file size to read (in bytes) : "
+ fis.available());
int content;
while ((content = fis.read()) != -1) {
// convert to char and display it
System.out.print((char) content);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
I have come up with this..
public class BufferedRedeem {
public static void main(String[] args) {
BufferedReader br = null;
long startTime = System.currentTimeMillis();
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C://abcd.log"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Total execution time taken in millis: "
+ elapsedTime);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}