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?
Re: Java.lang.OutOfMemoryError
Seems that it can handle up to about 50 megs and then that is that.
Re: Java.lang.OutOfMemoryError
you need to specify larger heap
Quote:
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
http://blogs.sun.com/watt/resource/j...ions-list.html
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.
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?