Results 1 to 3 of 3

Thread: BufferedReader

  1. #1
    vidhya.sk is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    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?
    code:

    import java.io.*;
    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
    Posts
    21
    Rep Power
    0

    Default

    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();

    stopWatch.start();

    String line = null;
    long totalLinesProcessed = 0l;

    while((line=br.readLine())!=null){
    totalLinesProcessed ++;
    StringUtils.split(line, "|");
    }


    stopWatch.stop();

    br.close();

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

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    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, 07:26 PM
  3. BufferedReader .mark(int readAheadLimit)
    By ShoeNinja in forum New To Java
    Replies: 1
    Last Post: 11-16-2007, 10: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
  •