Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem to display characters under Linux

Status
Not open for further replies.

laffreuxthomas

Programmer
Sep 3, 2002
20
FR
Hi !

I've just installed a Debian, but Java programs cannot display french characters...

This program :
Code:
    for (int i=0; i < 1000; i++) {
      System.out.println(i + &quot; &quot; + (char) i);
    }
display the first 127 characters, and then '?' for number upper to 127 :
Code:
   ...
    123 {
    124 |
    125 }
    126 ~
    127
    128 ?
    129 ?
    130 ?
    131 ?
    ...

- I don't have this problem under Windows.
- Non-Java programs of Linux write correct french characters
- All Java software have this problem
- I have installed the package xfonts-intl-european

Any idea ?

Thomas
 
Hi laffreuxthomas,
You say that:
- I don't have this problem under Windows
but then you say:
- All Java software have this problem
I'm not quite sure what you mean by that. Can you be a little clearer?

In any event, after looking at the
Code:
PrintStream[code] class, which is what [code]System.out
is, you can specify the character encoding
Code:
PrintStream (OutputStream out, boolean autoFlush, String encoding)
from one of a few encodings that must be in the JDK. Those encodings are below, taken from
Code:
java.nio.charset.CharSet
API.

Standard charsets
Every implementation of the Java platform is required to support the following standard charsets. Consult the release documentation for your implementation to see if any other charsets are supported.
[tt]
US-ASCII Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
ISO-8859-1 ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
UTF-8 Eight-bit UCS Transformation Format
UTF-16BE Sixteen-bit UCS Transformation Format, big-endian byte order
UTF-16LE Sixteen-bit UCS Transformation Format, little-endian byte order
UTF-16 Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark
[/tt]
I would try ISO-8859-1 to see how that works. From my tests, I believe
Code:
System.out
uses US-ASCII by default. I have not had the chance to try these on Linux, so I could be way wrong, but I think there's a good chance this will fix you problem. Let me know, I'm interested to hear how it works out. [smile]

The test code I used is similar to the code posted above, modified to create a custom
Code:
PrintStream
wrapped around
Code:
System.out
and specification of the character encoding. The code is below:
Code:
import java.io.*;

public class CharacterTest {
  public static void main (String[] args) {
		
    PrintStream out;
		
    try {
      out = new PrintStream (System.out, true, &quot;ISO-8859-1&quot;);
    }
    catch (IOException excpetion) {
      return;
    }

    for (int i=0; i < 1000; i++) {
      out.println (i + &quot; &quot; + (char) i);
    }
  }
}
I hope this helps you out,
MarsChelios
 
Thanks a lot for your answer.

I have tried with :
* ISO-8859-1
* UTF8

but the result is similar : now it is not '?' but a square for characters upper than 127... I think i have a problem in my Linux configuration. But why non-java applications havn't any problem ?

[tt]
You say that:
- I don't have this problem under Windows
but then you say:
- All Java software have this problem
I'm not quite sure what you mean by that. Can you be a little clearer?
[/tt]

Ok i should say &quot;Each Java software has this problem under Linux&quot; but not under MS Windows ...
-> Jbuilder and Jext have the same problem than my programs

Thomas
 
Thanks for your code !
I write characters into a file, then i open the output file with a non-Java editor... And it's working !

So there is a problem of JDK configuration ???

[tt]
static private void testCharactersInFile() {
StringBuffer sb = new StringBuffer();
for (int i=110; i < 200; i++) {
sb.append(i + &quot; = &quot; + (char) i + '\n');
}
writeFile(&quot;test.txt&quot;, sb.toString());
}

static private void writeFile(String filename, String content) {
try {
PrintStream out = new PrintStream (
new FileOutputStream(filename),
true, &quot;ISO-8859-1&quot;
);
out.print(content);
out.close();
}
catch (IOException e) {
System.err.println(&quot;Error when create &quot; + filename);
e.printStackTrace();
}
}
[/tt]

Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top