I came across the following problem: I'd like to read a file into a string so that each byte is converted to a character by just setting the MSB to '\0' and LSB to the byte itself. I know there is a way of doing that (readLine() from java.io.DataInputStream), but the specs say its deprecated:
Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
I think, however, that the latter solution uses the default encoding to convert bytes to characters (that's what InputStreamReader is for anyway).
How to accomplish what I need without using deprecated methods?
Thanks for your input. I know it is a solution, and I'm actually using it. The problem, however, remains--now, how to change byte to a String without using deprecated methods (you know, Strings are nicer to work with than raw byte arrays ). Do I really have to construct the string myself char after char?