I am attempting to make a Dictionary like software. The way this software will work is that You will be able to enter a word into a search bar, and the dictionary will search for the word. It will display the word, the pronunciation and the meaning of the word in the frame. I decided to use an Object Output Stream to read in the words (which will be saved whenever a new word is added). My problem occurs with the encoding used by the ObjectOutputStream when exporting the class. I am using Korean characters in my program, and these characters (when written and then read back in) appear as question marks. I am wondering if there is any way to change the encoding for the ObjectOutputStream. If anyone has any other solutions I will be glad to hear them.

Thanks for any help and suggestions.

this might help... the part about converting the encoding standard to UTF-8. unless of course you have already tried that.

Thanks for the reply. I found something similar, and I changed my eclipse console to display in UTF-8, and that solved that problem. Then just to make sure I did a test print to a JLabel and it showed up correctly there. I guess this was more of an IDE problem than a Java problem.

thats good.
while your doing that , would you mind giving some feed back on whether

public Scanner(InputStream source, String charsetName)

does a good job too ? you can set the charsetName to UTF-8 . i havent done anything of this sort before, maybe we can both learn something new.

I'm not sure about that constructor of the Scanner class, but when I use the new Scanner (File) it reads in the characters correctly.

so reading as well as printing out both are working ok ? like the example in the S.O forum , doing a System.out.println("<korean chars here>") prints out the chars all right ?

Mine is working correctly. I wrote this sample code to demonstrate.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class Main {

    public Main(){
        System.out.println("Test Korean: 안녕하세요\n");

        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(new File ("test.txt")));

            System.out.println("Writing: English");
            out.write("English\n");
            System.out.println("Writing: 한국어");
            out.write("한국어\n");
            System.out.println("Writing: I wonder if it worked");
            out.write("I wonder if it worked");

            out.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            Scanner in = new Scanner (new File ("test.txt"));
            while (in.hasNext()){
                System.out.println("Read: " + in.nextLine());
            }
            in.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new Main();



    }

}

Just make sure you have your IDE's console set to display UTF-8

commented: this is going to help a lot of people. +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.