This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Cannot allocate memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " Cannot allocate memory" Watch " Cannot allocate memory" New topic
Author Cannot allocate memory

Preeti Prakash

Joined: May 18, 2005
Posts: 9
My program reads from the database and writes to a file.

1. I am running this on Weblogic 8.1
2. Linux OS.

This program has worked many times before without throwing this exception and is also working now (without me making any changes)
I would like to find the root cause of the problem to ensure that this exception is not thrown again.

The is thrown while writing to the file. Can anyone tell me what are the possible causes for this.

Harinath Kuntamukkala
Ranch Hand

Joined: May 17, 2005
Posts: 37
In Which condition u r getting this error.....
Joe Ess

Joined: Oct 29, 2001
Posts: 8839

Welcome to the JavaRanch, Preeti.
Please don't post the same question in multiple forums. Everyone here at the ranch reads several forums so you are not increasing your audience. Not to mention if you get two replies to your two posts, you are probably wasting one of your replier's time.
As for your question, you are not giving us enough information about your problem. At a bare minimum you should give us the exception stack trace and a few of the lines of code where the exception occurs. Since it appears to be a memory problem, you should also examine the memory state of the application (i.e. how big the VM is, how much memory the server has, what memory settings the JVM has, etc.). For more hints on getting help, read over How To Ask Questions The Smart Way.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Preeti Prakash

Joined: May 18, 2005
Posts: 9
Oops! Sorry about posting the same question in two forums.

1. This exception is thrown when I am copying my file from one folder to another. Here's a part of the code.

FileInputStream fin = null;
FileOutputStream fout = null;
try {
fin = new FileInputStream(source);
fout = new FileOutputStream(dest);

byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
fout.write(buffer, 0, count);
count =, 0, buffer.length);
} while (count != -1);
finally {
if (fout != null) {
if (fin != null) {

2. Here's the stack trace: Cannot allocate memory
at Method)
at;II)I(Unknown Source)
at Source)
at[BII)V(Unknown Source)
at[BII)V(Unknown Source)

3. JVM memory -
Max memory -384 MB
Total memory - 254 MB
File size I am trying to copy - 79 MB
[ May 19, 2005: Message edited by: Preeti Prakash ]
Joe Ess

Joined: Oct 29, 2001
Posts: 8839

I don't see any problems with what you've posted. Do you have plenty of disk space? Does the input file exist? Does the output directory exist? Does the user Weblogic is running as have permission to write to it? Since you are using Rockit you may want to try searching for or posting your problem in the bea support newsgroups.
Preeti Prakash

Joined: May 18, 2005
Posts: 9

Yes, I do have plenty of disk space (otherwise it would throw me a 'Exception: There is not enough space on the disk' exception.)

Yes, the input file exists.

The output directory does not necessarily exist, but if it does not exist, it would be created.

Yes, the Weblogic user has permissions to write.

Only once has my program thrown this exception. It has worked without throwing this error before and even now continues to work without throwing the error. My only purpose is to find the root cause so that I would be able to handle this condition in my code and ensure that the same error is not thrown again.

Thanks for your time. I will also look into the bea support newsgroups.
Ranga Kalidindi

Joined: Mar 04, 2005
Posts: 17
Did you try to to simulate your exception. Just thought may be we can try these:
- supply a zero byte 'source' file
- supply an invalid 'source' and/or 'dest' file Name (may be have a special character like '%' in the filename)

I am sure if we can simulate (this exception) we can find a solution and be ready for it.
Preeti Prakash

Joined: May 18, 2005
Posts: 9
I did try simulating the exception, but no luck there. I tried your suggestions:
1. A zero byte 'source' file successfully completes the process.
2. An invalid 'source' and/or 'dest' file name throws a

I agree with you that if we could simulate the exception, there are more chances of finding the problem, but I am not able to simulate it.

Thanks for your time. I will let you know if I find the problem.
I agree. Here's the link:
subject: Cannot allocate memory
Similar Threads
Really opening and saving REAL files!!!???
Exception Question
Checked Exception Cannot allocate memory
Need Suggestions on I/O Applet Question