CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Unicode File Reading (http://www.codingforums.com/showthread.php?t=208754)

DELOCH 11-07-2010 08:14 PM

Unicode File Reading
 
I want to make a dictionary file that writes out a corresponding language in that language in a message dialog

My file as is:
Russian: русский
English: english
French: francais

I saved it in notepad as UTF-8
and have the following code
Code:

import java.io.*;
import javax.swing.*;

public class EnglishTester
{
    public static void main(String[] args)
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));       
        String fileName = "LanguageDictionary.txt";

        File file = new File(fileName);

        if (!file.exists())
        {
            System.out.println("Dictionary not found!");
            System.out.println("Terminating...");
            System.exit(0);
        }
        else
        {
            try {
                FileInputStream dictInputStream = new FileInputStream(file);
                InputStreamReader dictStreamReader = new InputStreamReader(dictInputStream , "UTF-8");
                BufferedReader dictionaryReader = new BufferedReader(dictStreamReader);

                //System.out.println((String)dictionaryReader.readLine());
                String temp = new String(dictionaryReader.readLine().getBytes(), "UTF-8");
                System.out.println(temp);
            } catch (UnsupportedEncodingException ex1) {
                System.out.println("unsupported");
            } catch (IOException ex2) {
                System.out.println("other exception");
            }
        }
    }
}

However, instead of outputting
Russian: русский

It outputs
?Russian: ???????

And yes, I know I am using PrintStream for this, I tried JOptionPane.showMessageDialog and the results were identical.

Anyone have any idea how I can make this work?


All times are GMT +1. The time now is 10:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.