how to read a file which contains more than 95000 <95 thousand> lines in java.

Edited 5 Years Ago by techgig: n/a

What kind of problems are you running into? If you can read a couple of lines, you can read 95K lines...

When i doing this job i got this type of error

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuffer.append(Unknown Source)

As I suspected, you are running out of heap space. When spawning the JVM process, pass in the following switch as JVM argument: -Xms128m -Xmx128m .

If you are invoking the java process from the command line, you can use:

java -Xms128m -Xmx128m pkg.MainClass

If you are using an IDE like Netbeans or Eclipse, refer the relevant documentation (i.e. google for "set heap size netbeans/eclipse").

Another variant of this exception is when you run out of permgen (permanent generation) space. Read this article for more details.

And think about whether you actually need all "95000 lines" in memeory at the same time. You would be better off reading a line, processing that line, reading the next line. Only rarely do you actually need all of the data in memory at the same time.

I agree with masijade and tamaris. Maybe the OP can shed more light on the original problem and we can provide a more detailed algorithm to deal with his issue.

But anyways, S.O.S thanks for the info. It will probably be useful at some point in the future (to me, anyways).

Jake Clawson

This article has been dead for over six months. Start a new discussion instead.