I'm implementing a huffman coding program. I encode and decode an entire book, so finding new line characters is very important, and something I overlooked, unfortunately. Currently, I use a method to read the small book into a String that is then returned, see below:
private String readFile(String filename) {
String curLine;
String toReturn = "";
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
try {
while ((curLine = reader.readLine()) != null) {
toReturn += curLine;
}
} catch (IOException e) {
System.out.println(e);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
return toReturn;
}
This works great for regular characters, but not for things like a newline (I know there is a word for these types of "characters" but I'm blanking on it right now). Anyways, my question is how can I change the current method to also pickup newLine characters, or would I need to do something completely different. I suspect readLine() is gonna do me no good now because of this, but I wanted to check here for some input.
Everything else in my program works great, but the fact that newlines are not taken into account messes up my whole Huffman Tree and I'm sure you understand what happens from there. Any suggestions for what I can do to pickup newlines would be appreciated. Thanks!