Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2010, 08:14 PM   PM User | #1
DELOCH
Regular Coder

 
DELOCH's Avatar
 
Join Date: Apr 2006
Location: Canada
Posts: 537
Thanks: 4
Thanked 2 Times in 2 Posts
DELOCH is an unknown quantity at this point
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?
DELOCH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:06 AM.


Advertisement
Log in to turn off these ads.