PDA

View Full Version : Unable to display special characters in Java



330toSRT8
03-08-2007, 10:03 PM
I wrote a program that traverses a directory for files of a given extension and then displays the absolutePath in a JList. Double-clicking on a filename will open it in the registered program. It works perfectly for English filenames. The problem is when I have other characters in the filename. For example, if I have a file titled "Mexico.txt" with an accented e, it shows up in the list with a block in place of the e. So the first problem is not being able to properly display the special characters. Next, if I double-click that file it sees the absolutePath as "m%3Fxico.txt" which I'm guessing is some sort of unicode encoding. Unfortunately, that encoding is not handled properly by the Runtime.getRuntime() method. I get a "file does not exist" error. All features work fine with English characters.

I have tried the JRE that comes with Knoppix 5.1.1 as well as fresh installs of JRE5 and JRE6 with the same results. In Windows Vista the accented characters appear properly when using JRE5 and JRE6.

Any help with these issues is greatly appreciated.

kirol
03-09-2007, 08:31 AM
What is your locale? Type "echo $LANG" in a konsole. I am guessing you need a Unicode locale for proper international support (e.g. en_US.UTF-8). You may also need to specify the character set your filesystem uses to encode filenames (as an option is /etc/fstab).

330toSRT8
03-09-2007, 08:57 AM
Echo $LANG returns C
just the single letter C

Here's the thing. I can create files in KDE all day long with accented characters. I also added the Spanish keyboard layout so I can easily type accented characters and it works perfectly. In the terminal when I do ls in the folder with accented filenames, the accented letters appear as a "?" (M?xico, for example). But I can do cat Mexico (accented e) and it displays the contents properly.

kirol
03-09-2007, 09:11 AM
Open a konsole, then type "export LANG=en_US.UTF-8" (C is definitely ascii-only). Then retry ls, and launch your java program (from the command line so it picks up the new locale). If this helps, you may want to refine with a unicode-enabled Spanish locale. And you haven't told us what kind of FS you're looking at, if your knoppix is HD-installed and if you're using a lang=xy cheatcode...

330toSRT8
03-09-2007, 07:06 PM
I tried what you suggested and I know it took effect because echo $LANG returned export LANG=en_US.UTF-8
the ls command listing still shows a ? in place of accented characters. But the actual line where I'm typing commands will display accents properly.
I started the java app from the same command line and it still puts a block in place of accented characters. I also tried the locales en_US and es_US (Spanish, I think) with the same results.

Next, I ran "dpkg-reconfigure locales" and selected "all locales." Same results.
Then I ran "locale-gen." Same results.

I did an HD install from the KNOPPIX DVD 5.1.1 with the option that makes it run live the live DVD. File system is reiserFS.

kirol
03-09-2007, 09:15 PM
I am seeing exactly all the symptoms you describe with my copy of the knoppix 5.1.0 CD running under VMWare player. My regular debian sarge install, OTOH shows filenames with accented characters without any problem (konq, xterm, ls, java...). LANG is set to en_GB (not even explicitly utf8), and the FS is ext3 - but i doubt it matters. Either locale support is broken in knoppix, or the setting that would correct things escapes me, sorry...

kirol
03-11-2007, 10:47 PM
Hi "330toSRT8", I don't know if you have solved your problem but I came across this entry (http://www.debian.org/doc/manuals/reference/ch-tune.en.html#s-l10n) in the debian FAQ which might help you.

330toSRT8
03-12-2007, 12:14 AM
Nope, haven't solved it yet. Thanks for the link. It looks promising. I'm gonna try some of those things.

joakimk
06-06-2007, 08:08 AM
Hey 330toSRT8!

Did you ever figure out the charset/Java/Knoppix problems? I'm having exactly the same problem; please see my post! (http://www.knoppix.net/forum/viewtopic.php?p=113557) :)

330toSRT8
06-06-2007, 07:04 PM
Hey 330toSRT8!

Did you ever figure out the charset/Java/Knoppix problems? I'm having exactly the same problem; please see my post! (http://www.knoppix.net/forum/viewtopic.php?p=113557) :)
Nope, I haven't found the answer yet.