View Single Post

  #4 (permalink)  
Old 09-01-2005
Juha Laiho
 
Posts: n/a
Default Re: problem with java, ASCII and Linux

fcastillo@hostgreen.com said:
>I has a Linux RedHat 9.0 with a jre1.5.0_04 (rpm package of Sun).
>
>I has a problem with ASCII , for example :


No, you have a problem with non-ASCII characters. ASCII is US-ASCII,
a-z, numerics and a small set of punctuation and special characters.

>import java.io.*;
>
>
>public class HolaMundo
>{
>public static void main (String[] args)
>{
>System.out.println("Holá Múndo");
>}
>}


.... so, two non-ASCII characters.

>this programs runs ok on my windows jdk so it prints "Holá Múndo",
>but when i run the same HolaMundo.class program on my linux redhat it
>prints "Holá Múndo"


Appears that you have some partially utf-8 -based environment.
That is, your environment states that you're using utf-8 as your
character encoding, and Java outputs sequences that would, in
true utf-8 environment provide the letter glyphs you were expecting.
Instead, your terminal emulator chooses to display the output in
some other encoding, perhaps iso-8859-1.

It used to be possible to force the encoding used by applications
with a system property named file.encoding, but at least the
tests I ran just now seem to indicate that the system property
is overridden by the locale environment variables.

You'll need to tell (by using LC_CTYPE environment variable)
to your Java VM which character encoding is used by your terminal
emulator. If it's iso-8859-1, you could use something like
LC_CTYPE=es_ES.iso88591 java Hola
to run your program on the command line.

And yes, character set issues (when you're working with anything
but US-ASCII) are a pain. And have been for more than two decades
already.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)