|
-
October 13th, 2009, 10:33 PM
#1
Java.lang.OutOfMemoryError
"Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space"
Ok, so I have a problem that is giving me this error and I am hoping that there might be someone who could help me out.
Code:
private String CalcFileSize(){
System.out.println("Calculating Size of File");
File _tempFile = new File (fileName.getText());
System.out.print(_tempFile.length());
byte [] _fileSizeGetter = new byte [(int)_tempFile.length()];
_fileSizeToSend = _fileSizeGetter.length;
String _sendFileSize = Integer.toString(_fileSizeToSend);
System.out.println("File Size Calculated");
return _sendFileSize;
}
Ok, this function basically creates a File called _tempFile and loads something into it (for example, if fileName.getText() == "source.pdf" then it will grab that file and throw it into _tempFile). The problem occurs when I use a large file. Particularly something like a 200meg file. Anyone have a suggestion on a possible way around this?
-
October 13th, 2009, 10:41 PM
#2
Re: Java.lang.OutOfMemoryError
Seems that it can handle up to about 50 megs and then that is that.
-
October 14th, 2009, 12:38 AM
#3
Re: Java.lang.OutOfMemoryError
you need to specify larger heap
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
http://blogs.sun.com/watt/resource/j...ions-list.html
-
October 14th, 2009, 02:01 AM
#4
Re: Java.lang.OutOfMemoryError
Much better idea is not to read the whole file at once, read a bit and increment a counter, keep on going untill end of stream. If you simply keep maxing your heap size, that is a row never ending. There are always larger files.
-
October 14th, 2009, 07:39 AM
#5
Re: Java.lang.OutOfMemoryError
I do not see anything in your code that indicates what kind of input/output stream you are using. I routinely read and write files over 500MB here without having any OutOfMemory errors. Are you using BufferedInputStream?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|