aspose file tools*
The moose likes I/O and Streams and the fly likes java.io.IOException: Cannot allocate memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "java.io.IOException: Cannot allocate memory" Watch "java.io.IOException: Cannot allocate memory" New topic
Author

java.io.IOException: Cannot allocate memory

Preeti Prakash
Greenhorn

Joined: May 18, 2005
Posts: 9
Hi,
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 java.io.IOException is thrown while writing to the file. Can anyone tell me what are the possible causes for this.

Thanks.
Harinath Kuntamukkala
Ranch Hand

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

Joined: Oct 29, 2001
Posts: 8971
    
    9

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.


[How To Ask Questions On JavaRanch]
Preeti Prakash
Greenhorn

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 = fin.read(buffer, 0, buffer.length);
} while (count != -1);
finally {
if (fout != null) {
fout.close();
}
if (fin != null) {
fin.close();
}
}

2. Here's the stack trace:

java.io.IOException: Cannot allocate memory
at COM.jrockit.io.FileNativeIO.write(III)I(Native Method)
at COM.jrockit.io.NativeIO.write(Ljava.io.FileDescriptor;II)I(Unknown Source)
at COM.jrockit.io.NativeIOOutputStream.write(II)V(Unknown Source)
at COM.jrockit.io.NativeIOOutputStream.write([BII)V(Unknown Source)
at java.io.FileOutputStream.write([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
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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
Greenhorn

Joined: May 18, 2005
Posts: 9
Hi,

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
Greenhorn

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)
anyother..

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

Joined: May 18, 2005
Posts: 9
Hi,
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 java.io.FileNotFoundException

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.
 
wood burning stoves
 
subject: java.io.IOException: Cannot allocate memory