How to read properties file in Greek using Java

Posted by Subhendu Mahanta on Stack Overflow See other posts from Stack Overflow or by Subhendu Mahanta
Published on 2010-05-29T02:49:30Z Indexed on 2010/05/29 2:52 UTC
Read the original article Hit count: 291

Filed under:

I am trying to read from a properties file which have keys in English & values in greek.My code is like this:

public class I18NSample {

static public void main(String[] args) {

  String language;
  String country;

  if (args.length != 2) {
      language = new String("el");
      country = new String("GR");
  } else {
      language = new String(args[0]);
      country = new String(args[1]);
  }

  Locale currentLocale;
  ResourceBundle messages;

  currentLocale = new Locale(language, country);

  messages =
    ResourceBundle.getBundle("MessagesBundle",currentLocale, new CustomClassLoader("E:\\properties"));

  System.out.println(messages.getString("greetings"));
  System.out.println(messages.getString("inquiry"));
  System.out.println(messages.getString("farewell"));

}

}

import java.io.File; import java.net.MalformedURLException; import java.net.URL;

public class CustomClassLoader extends ClassLoader {

private String path;



public CustomClassLoader(String path) {
    super();
    this.path = path;
}



@Override
protected URL findResource(String name) {
    File f = new File(path + File.separator + name);
    try {
        return f.toURL();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return super.findResource(name);
}

}

MessagesBundle_el_GR.properties greetings=??µ. ?a??et? farewell=ep?f. a?t??

inquiry=t? ???e?s, t? ???ete

I am compiling like this javac -encoding UTF8 CustomClassLoader.java javac -encoding UTF8 I18Sample.java

When I run this I get garbled output.If the properies file is in English,French or German it works fine. Please help. Regards, Subhendu

© Stack Overflow or respective owner

Related posts about encoding