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!
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.
> 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 >

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
> > 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 >
