cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.OutOfMemoryError when reading file ~ 50MB

Former Member
0 Kudos

Hi everybody,

I get java.lang.OutOfMemoryError when reading a very huge file:

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

// the following thows the error

while ((strLine = br.readLine()) != null) {

How can I read huge files?

Thanks regards

Mario

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello

try to increase the heap size when running your java program with the command line option -Xmx

java -Xmx256m your.program

and process the data efficiently inside the while loop

regards franz

reward points if useful

Former Member
0 Kudos

Hi franz,

how and where do I have to incease the heap size?

Is the any other option; e.g. read the file not a string but as stringBuffer?

Regards Mario

Former Member
0 Kudos

Hello

from where are you running your java program, on a server, from a IDE....?

You need to set a command line parameter to increase the heap size, in Eclipse IDE for example this can be done in the 'Run' Dialog

could you maybe post more of your source code?

regards franz

Former Member
0 Kudos

Hi franz,

Eclipse SDK

Version: 3.2.1

Regards Mario

volker_schropp
Explorer
0 Kudos

Hi Mario,

in the menu of eclipse, go to Run->Open Run Dialog. Then choose your Java Application and switch to the tab Arguments in the right part of the dialog.

In the field text-editor, you could insert the value '-Xmx256m' (use the string between the single quotation marks).

Apply your settings and start your program.

Greets