Re: (Probably simple) problem with displaying Unicode characters
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 10:24:40 -0800
mfeher@xxxxxxxxxxx wrote:
Hi all,
I am getting back into Java programming after a long layoff and now
that I'm doing it everyday, I'm remembering the things I enjoyed about
it and the things that I find maddening. :) I'm trying to write a
simple program to both test my old skills as well as develop code for
use later, when I will need it on a later project.
Right now I'm simply trying to display a Unicode character in the
Eclipse output window. I have a full-up WinXP system with a ton of
fonts (more on that in a moment) but don't seem to see what is wrong
with my program.
I never did much with Unicode years before and never had it succeed for
me then, either, if I recall correctly. But I don't think the
process/requirements are that hard:
- Have Unicode fonts installed
- Use the correct encoding in the Java output stream
- Look up the correct character(s) in the Unicode tables
Here's the program as it stands now (one file called Main.java):
import java.io.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws
UnsupportedEncodingException {
String unicodeMessage = "\u03B2";
// Print out a Unicode character
System.out.println("We attempt to print out the Greek character
beta:");
PrintStream output = new PrintStream(System.out, true, "UTF-8");
output.println(unicodeMessage);
}
}
Here's the output I get:
We attempt to print out the Greek character beta:
β
Please, can someone spot the (probably simple) error in my
setup/coding? Thanks!
Mike
Mike:
The default character set is UTF-16 which will display your 'beta' character just fine. It won't however display on the console, at least I know it won't on a Winblows XP system.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws UnsupportedEncodingException {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
f.add(new Label("\u03b2"));
f.pack();
f.setVisible(true);
}
}
--
Knute Johnson
email s/nospam/knute/
.
- Follow-Ups:
- Re: (Probably simple) problem with displaying Unicode characters
- From: Zerex71
- Re: (Probably simple) problem with displaying Unicode characters
- From: Roedy Green
- Re: (Probably simple) problem with displaying Unicode characters
- References:
- Prev by Date: Re: Java Data Mapper
- Next by Date: Re: Update view of database on multiple web clients
- Previous by thread: (Probably simple) problem with displaying Unicode characters
- Next by thread: Re: (Probably simple) problem with displaying Unicode characters
- Index(es):
Relevant Pages
|