Japanese Input and Display

I'm a student who is looking to write a flashcard program for my Japanese vocabulary. The idea was to have the program read in the vocab from a text file, but I'm having issues with the idea of encoding. I was wondering if someone could give me a step-by-step guide of some sort to allowing Java to read in and display Japanese font. I'm running on Java 6. Thanks!

[374 byte] By [cryptic_stara] at [2007-11-26 19:33:37]
# 1
Java text -- String object -- consists of Unicode characters.Japanese is a small sub-set of Unicode character set.So you should have no problem handling it in Java code.
hiwaa at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 2
Well, it reads it in, but it won't output it in the Japanese font....
Cryptic_Stara at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 3
Basically, I have a single hiragana character saved in a text file with unicode encoding. I try to read it in with scanner and then output it either to the console or a JOptionPane, and instead of getting the character, I get garbage.
Cryptic_Stara at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 4
You should have fonts on your machine and proper fontconfig file in your jre/lib directory. ... And, try call Locale.setDefault() with JAPANESE Locale.Message was edited by: hiwa
hiwaa at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 5

> Basically, I have a single hiragana character saved

> in a text file with unicode encoding. I try to read

> it in with scanner and then output it either to the

> console or a JOptionPane, and instead of getting the

> character, I get garbage.

And I think we should see your code doing your I/O for Japanese.....

hiwaa at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 6

Scanner scan=null;

try {

scan = new Scanner(new File("C:/test2.txt"));

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

while(scan.hasNext()) {

System.out.println("\n\n"+scan.next()+"\n");

}

As for my fontconfig.properties file, I think I've modified it correctly...I've added lines for Japanese, such as

serif.bolditalic.japanese=MS Mincho

Cryptic_Stara at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 7

> > Scanner scan=null;

> try {

> scan = new Scanner(new File("C:/test2.txt"));

> } catch (FileNotFoundException e) {

> // TODO Auto-generated catch block

> e.printStackTrace();

> }

> while(scan.hasNext()) {

> System.out.println("\n\n"+scan.next()+"\n");

> }

>

>

> As for my fontconfig.properties file, I think I've

> modified it correctly...I've added lines for

> Japanese, such as

>

> serif.bolditalic.japanese=MS Mincho

You should not use java.util.Scanner for general I/O purpose.

Do like this:

// try/catch omitted for simplicity

String charSetName = "......"; // charset used in your text file

String line = null;

BufferedReader br = new BufferedReader

(new InputStreamReader(new FileInputStream("C:/test2.txt"), charSetName));

while ((line = br.readLine()) != null){

System.out.println("\n\n" + line + "\n");

}

For chasetname, see JDK documentation:

/guides/intl/encoding.doc.html

hiwaa at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...
# 8
I have still not found an appropriate charset to display correctly. The problem wouldn't lie in eclipse's console, would it?
cryptic_stara at 2007-7-9 22:06:15 > top of Java-index,Java Essentials,Java Programming...