Results 1 to 3 of 3

Thread: BufferedReader

  1. #1 is offline Member
    Join Date
    Sep 2008
    Rep Power

    Default BufferedReader

    Hi everyone!

    I am using BufferedReader to read a textfile and finding the time taken to read the file.

    The time taken to read kept varying from one run to another in a random
    manner.Can anyone tell me what could be the reason behind it?

    class fileread{
    public static void main(String args[]) throws IOException
    BufferedReader br = new BufferedReader(new FileReader("c:\\\\sourcefile.dat"));
    long start;
    long end;
    String str;
    start = System.currentTimeMillis();
    while((str = br.readLine()) != null)

    end = System.currentTimeMillis();

    System.out.println("time taken " + (end-start));


    Run1 - 938 ms
    Run2 - 929 ms
    Run3 - 923 ms
    Run4 - 939 ms
    Run5 - 922 ms.

    Thank you!

  2. #2
    nishant is offline Member
    Join Date
    Sep 2008
    Rep Power


    hi....this what i understood from your last message.....might this help!
    to check the time taken to read the file.

    public class TokenizeFile {

    public static void main(String[] args) throws Exception {
    File file = new File("hugefile.txt");
    BufferedReader br = new BufferedReader(new FileReader(file));

    StopWatch stopWatch = new StopWatch();


    String line = null;
    long totalLinesProcessed = 0l;

    totalLinesProcessed ++;
    StringUtils.split(line, "|");



    System.out.println("Total lines processed = "+totalLinesProcessed+" Time taken = "+stopWatch.getTime() +" ms");

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    time taken to read kept varying
    What else was your OS doing while the program was running? If the OS does something during your program, that will change the timings.

Similar Threads

  1. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 02:56 PM
  2. Reading int values using BufferedReader
    By Java Tip in forum Java Tip
    Replies: 2
    Last Post: 01-24-2008, 08:26 PM
  3. BufferedReader .mark(int readAheadLimit)
    By ShoeNinja in forum New To Java
    Replies: 1
    Last Post: 11-16-2007, 11:58 PM
  4. Help with BufferedReader in java
    By carl in forum New To Java
    Replies: 2
    Last Post: 07-31-2007, 07:20 AM
  5. BufferedReader empty
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts