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?