Java Heap Memory Problem!!
The code below is my class.
I read from a file with size of approx. 80Mbytes.
And i get the following error
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.String.concat(String.java:2001)
at Group_Referenced_KWDS_By_Article.main(Group_Referenced_KWDS_By_Articl
e.java:40)
It seems that my tempKWDS gets too long while it shouldn't.
Any proposals?
Tip: My class actually reads from a file and tries to minimize it's length by concatenating lines with the same 1st element of the file. ( ex. ID1 , good ID1 , modest--to--ID1:: good , modest )
import java.io.*;
import java.util.*;
//import java.lang.*;
publicclass Group_Referenced_KWDS_By_Article{
publicstaticvoid main(String[] argz){
try{
String linefeed;
File fin =new File("Keywords Referenced ByArticle.txt");
FileInputStream fis =new FileInputStream(fin);
BufferedReader br =new BufferedReader(new InputStreamReader(fis));
BufferedWriter out =new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(
new File("Grouped Referenced KWDS ByArticle.txt"))));
Hashtable htable =new Hashtable(100000);
String tempKWDS="";
StringBuffer empty =null;
String currentUT_ITEM ="";
String previousUT_ITEM =null;
String[] line =new String[2];
String tofileValue="";
String tofileKey ="";
String tofile ="";
while((linefeed=br.readLine())!=null){
line = linefeed.split("::");
currentUT_ITEM=line[0];
if(currentUT_ITEM.equalsIgnoreCase(previousUT_ITEM)){
tempKWDS=htable.get(currentUT_ITEM).toString();
tempKWDS = tempKWDS.concat(" :: ");
tempKWDS = tempKWDS.concat(line[1]);//LINE 40 <
//htable.remove(currentUT_ITEM);
htable.put(currentUT_ITEM,tempKWDS);
previousUT_ITEM=currentUT_ITEM;
tempKWDS="";
}else{
tempKWDS ="";
tempKWDS = line[1];
htable.put(line[0],tempKWDS);
previousUT_ITEM=currentUT_ITEM;
}
}
Enumeration k = htable.keys();
while (k.hasMoreElements()){
tofileKey=null;
tofileValue=null;
tofile=null;
tofileKey = k.nextElement().toString();
tofileValue = htable.get(tofileKey).toString();
tofile=tofileKey.concat(" :: ").concat(tofileValue);
out.write(tofile);
out.newLine();
//System.out.println("Key " + key + "; Value " + (String) h.get(key));
}
br.close();
out.close();
}catch(Exception e){
System.out.println(e);
}
}
}

