Reading large files in java


General J2EE: Reading large files in java

  1. Reading large files in java (1 messages)

    Hi All

    I am trying to read the contents of an XML file thru servlets. The size of the file is around 1MB. How can I read the contents of the file using java? and the time taken to read the file should be reasonable.
    How do i do that? Can some out help m eout with the code for reading huge file. I tries with FileReader and reading charcter by character, but it takes a very long time.

  2. What exactly are you trying to do? If you just want to read the file and stote it locally use that wrappes the FileInputStream. Buffer size of 4096 or 8192 should probably be the best.
    However, if you try to process the XML, I'd suggest to use SAX )Simple API for XML) - see