Re: Reading lines of text from a MappedByteBuffer

Discussion in 'Java' started by mromarkhan@rogers.com, May 4, 2004.

  1. Guest

    peace be unto you


    "C:\Program Files\Java\j2sdk1.5.0\bin\javac.exe" -source 1.5 Speed.java
    "C:\Program Files\Java\j2sdk1.5.0\bin\java.exe" -version:1.5 Speed
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.charset.*;
    import java.io.*;
    import java.util.*;
    class Speed
    {
    public static void
    main(String [] s) throws IOException
    {
    Long startTime = System.nanoTime();
    FileChannel fc = new FileInputStream("c:/windows/desktop/omarnews.html").getChannel();
    MappedByteBuffer byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY,0, fc.size());
    Charset charset = Charset.forName("US-ASCII");
    CharsetDecoder decoder = charset.newDecoder();
    CharBuffer charBuffer = decoder.decode(byteBuffer);
    Scanner sc = Scanner.create(charBuffer).useDelimiter(System.getProperty("line.separator"));
    while(sc.hasNext())
    {
    System.out.println(sc.next());
    }
    fc.close();
    Long estimatedTime = System.nanoTime() - startTime;
    System.out.printf("Diff: %d", estimatedTime);
    }
    }



    Have a good day.
     
    , May 4, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Ward
    Replies:
    2
    Views:
    2,511
    Tim Ward
    Oct 2, 2003
  2. The POWER of 2WO
    Replies:
    2
    Views:
    1,544
    xarax
    Dec 2, 2004
  3. Claudio!

    MappedByteBuffer

    Claudio!, Sep 20, 2006, in forum: Java
    Replies:
    2
    Views:
    608
    Tim Ward
    Sep 20, 2006
  4. Me
    Replies:
    9
    Views:
    553
    Florian Weimer
    Jan 9, 2007
  5. Replies:
    5
    Views:
    1,056
Loading...

Share This Page