0

I need the character like 'шел' in my .properties file.

It seems like ISO 8859-1 (Which seems to be the default .properties encoding) doesnt like these, and displays them as ?.

I want to support this characters, what to do?

EDIT: I made it work now, but everytime I use this it converts my file from UTF-8 to ANSI (So the file gets replaced with the same file but then in ANSI), really weird. Code: http://pastebin.com/r0h3CKXF

Any idea why this happens??

Jonathan
  • 89
  • 10
  • Use a properties editor. They can also present several languages (files) side-by-side. They may present full Unicode text, but store it in IISO-8859-1,u-escaped as `\uXXXX`. – Joop Eggen Feb 15 '15 at 15:00

2 Answers2

1

Unicode can be encoded with \uxxxx in property files.

1

The Oracle JDK contains a tool named native2ascii that converts property files to Latin-1. Write your .property file in UTF-8, and then call

/path/to/jdk/bin/native2ascii -encoding utf8 input.properties output.properties

You can also read UTF-8 encoded .property files. See How to use UTF-8 in resource properties with ResourceBundle for a detailed description.

Community
  • 1
  • 1
ralfstx
  • 3,893
  • 2
  • 25
  • 41
  • And then? ResourceBundle reads it still as ISO 8859-1, which doesnt support these characters – Jonathan Feb 14 '15 at 20:16
  • This tool will convert all non-latin-1 chars into escape sequences (`\uxxxx`) – ralfstx Feb 14 '15 at 20:21
  • Is it possible to automate this with Java? (So it checks for convertable text / convert it every startup) – Jonathan Feb 14 '15 at 20:24
  • I don't think it is. However, you could write a tool that scans directories for .property files and converts them if you like. – ralfstx Feb 14 '15 at 20:29
  • @BammerbomTheKing Instead of just calling the one-argument `ResourceBundle.getBundle` method, call the getBundle method that takes both a name and a [ResourceBundle.Control](https://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.Control.html) argument. Pass in your subclass of ResourceBundle.Control which overrides the `newBundle` method to create a PropertyResourceBundle from a Reader which uses an explicit charset, rather than an InputStream. – VGR Feb 14 '15 at 20:37
  • I am currently using new PropertyResourceBundle(FileInputStream). How would I use ResourceBundle.Control now? – Jonathan Feb 14 '15 at 22:12