S
Steve
Hi,
I have a text file with some french lines saved in the UTF-16 format.
Most of the words can be represented easily with a byte but some special
accept alphabets are 16 bits. I'm trying to read this file in from a
MIDLET and so the only way I can do this is:
InputStream is = this.getClass().getResourceAsStream("file.txt");
byte[] data = new byte[50000];
is.read(data);
I am trying to draw each line on the canvas using the drawString
Graphics method. However, I am having difficulty finding 16bit letters
from the text file and displaying them correctly. If I convert each byte
to a char, most letters pass through except the 'special' ones, for
which I think I need to take the next byte in the stream and join it
together with the previous one. Even then, the problem is that Unicode
characters need to be represented like the following: '\u0045'. Now
since I am storing each character of a single line in a char array, I
can't seem to "join" two bytes and then add '\u' in front - it fails and
complains that this isn't a character but a string. I hope I was able to
express my problem clearly. This is what I'm doing:
char[] line = new line[150];
for (int i=0;i<150;i++) {
line = (char)data[lineOffset+i];
}
If I print line with Graphics.drawChars, it works but gives me weird
characters in place of actual single unicode characters - for a single
unicode character it gives me two characters.
In short, how do I tell that I'm about to stumble on a unicode character
by looking at the byte being returned and how can I 'join' two bytes to
represent a single character. Any help would be most appreicated.
Thanks,
Steve
I have a text file with some french lines saved in the UTF-16 format.
Most of the words can be represented easily with a byte but some special
accept alphabets are 16 bits. I'm trying to read this file in from a
MIDLET and so the only way I can do this is:
InputStream is = this.getClass().getResourceAsStream("file.txt");
byte[] data = new byte[50000];
is.read(data);
I am trying to draw each line on the canvas using the drawString
Graphics method. However, I am having difficulty finding 16bit letters
from the text file and displaying them correctly. If I convert each byte
to a char, most letters pass through except the 'special' ones, for
which I think I need to take the next byte in the stream and join it
together with the previous one. Even then, the problem is that Unicode
characters need to be represented like the following: '\u0045'. Now
since I am storing each character of a single line in a char array, I
can't seem to "join" two bytes and then add '\u' in front - it fails and
complains that this isn't a character but a string. I hope I was able to
express my problem clearly. This is what I'm doing:
char[] line = new line[150];
for (int i=0;i<150;i++) {
line = (char)data[lineOffset+i];
}
If I print line with Graphics.drawChars, it works but gives me weird
characters in place of actual single unicode characters - for a single
unicode character it gives me two characters.
In short, how do I tell that I'm about to stumble on a unicode character
by looking at the byte being returned and how can I 'join' two bytes to
represent a single character. Any help would be most appreicated.
Thanks,
Steve