I am a computer science student - second year. I was asked to prepare a project - by Hoffman Code. During the project I got stuck in the fault, I am in the project phase building the encoder. I get a file - and I have to encode it in bytes - according to the Hoffman code.
My question is how to encode the file in bytes - what I did: for example: I received the word "abca cadbara" in the file. And into another file I put the encoding but using a string and not in bytes.
the part of the code:
public static void writeOutputFile (String[] input_names, String[] output_names, Map<Character, String> codes)
{
FileInputStream input;
FileOutputStream output;
try
{
input = new FileInputStream(input_names[0]);
output = new FileOutputStream(output_names[0]);
for (int i = 0; i < (int) input.getChannel().size(); i++)
{
int x = input.read();
String codeOutput = codes.get((char) x);
//output.write(Integer.parseInt(codeOutput, 2));
for (int j = 0; j < codeOutput.length(); j++) {
output.write((int) codeOutput.charAt(j));
}
}
input.close();
output.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
How can I use bytes and not the string? Thanks for the help.