"Java heap space" Problem
Hi,
I have been told to start a new thread about this error message im getting.
My program is encoding a 23.6mb file.
Every time i run my program on this size of file i get this error message
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
I have tried to increase my memory space but it hasnt had an effect.
This is the command ive used.
java -Xms32m -Xmx512m
[432 byte] By [
carrics3a] at [2007-11-27 1:54:29]

This is the encoder java file that I have wrote
import java.io.*;
import java.util.*;
public class Encoder
{
public static void main(String [] args)
{
try{
Encoder testy = new Encoder();
DataInputStream In = new DataInputStream(new FileInputStream(args[0]));
DataOutputStream Out = new DataOutputStream(new FileOutputStream(args[1]));
Hashtable<String, Integer> dictionary = new Hashtable<String, Integer>();
//Populate the dicionary with characters
for(int i = 0; i < 256; i++)
{
String valOne = (char)i+"";
int valTwo = i;
dictionary.put(valOne, valTwo);
}
// Do encoding
testy.encode(In, Out, dictionary);
//close the Input file
In.close();
}
catch(IOException e){
e.printStackTrace();
}
}
public void encode(DataInputStream In, DataOutputStream Out, Hashtable<String, Integer> dictionary)throws IOException
{
try{
int dictionarySize= 256;
int reader = 0;
String addVal="";
int writeVal = 0;
String firstVal= (char)In.read()+"";
while(In.available()>0)
{
reader=In.read();
if(dictionary.containsKey(firstVal + (char)reader)){
firstVal = firstVal + (char)reader;
writeVal = dictionary.get(firstVal);
}
else
{
writeVal = dictionary.get(firstVal);
addVal = firstVal + (char)reader+"";
Out.writeShort((short)writeVal);
dictionary.put(addVal, dictionarySize);
dictionarySize++;
firstVal = (char)reader+"";
}
}
Out.writeShort((short)writeVal);
Out.flush();
Out.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}