Hello Folks, I would appreciate if you could provide some suggestion with regard to this problem here. I am trying to read a file that is 500 MB and put in StringBuffere and then put in a database. I would like to read the file into stringbuffer so that i don't have to make a multiple trips reading a line of that file and putting it into the database. but reading the whole file into buffer is giving "java.lang.OutOfMemoryError" error. do you guys have any suggestion on how i can achieve this? Also, the file could be even bigger than 500 MB. Thanks.
first thing is to increase the size of the heap that Java is using. If the file itself is 500MB, then the JVM is going to need more room than that to work with the file and do other stuff.... so, check out the heap commands:
particularly look at -Xmx and -Xms
If you know you're gonna use at least 500MB, maybe you should initialize your heap to 512MB, with a max size of 1024MB?
so your command would look like: java -Xms512m -Xmx1024m someClass