General J2EE: Reading large files in java
- Posted by: Chandrasekar Duraisamy
- Posted on: February 03 2004 06:39 EST
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.
What exactly are you trying to do? If you just want to read the file and stote it locally use java.io.BufferedInputStream 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 http://www.informit.com/content/index.asp?product_id=%7BC1ACDC39-2AF3-4BB2-A1AD-4BC90CD0244E%7D