4

I have a problem with .properties files in Netbeans. I use such files in order to provide some localized strings in my app.

Case 1

If I create a new .properties file in Netbeans (New -> Properties File) and I but some lines there:

INFO_OEFFNEN=Открыть информацию
FILE=Файл
SPRACHE=Язык

everything works fine and all strings are translated properly:

enter image description here

But if I open this file by means of Notepad++ I see what follows (Notepad++ recognizes the encoding, maybe incorrectly, as UTF-8):

INFO_OEFFNEN=\u041e\u0442\u043a\u0440\u044b\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e
FILE=\u0424\u0430\u0439\u043b
SPRACHE=\u042f\u0437\u044b\u043a

Case 2

If I create an UTF-8 encoded .properties file with Notepad++ containing the following lines:

INFO_OEFFNEN=Открыть информацию
FILE=Файл
SPRACHE=Язык

and open it in Netbeans I see this:

INFO_OEFFNEN=ÐÑкÑÑÑÑ Ð¸Ð½ÑоÑмаÑиÑ
FILE=Файл
SPRACHE=ЯзÑк 

In GUI I can see something very strange:

enter image description here

Case 3

I make the same as in case 2 but I in Netbeans I set the "use project encoding" property of a .properties file to true.

Now in Netbeans editor I see correct text (but 100% marked as "modified" by SVN). When I start the App strings looks like this:

enter image description here

Question:

I assume that the default encoding of properties files created by Netbeans is not UTF-8. How can I check which encoding does Netbeans use by default in this case?

I would like to write a short Java app which reads a .properties file (created by Netbeans), adds or replaces some lines and creates a new file which should be read by Netbeans correctly. Which encoding should I use in InputStreamReader?

Please give me some tips about this problem. Is my assumption about different default encoding in Netbeans correct? I'm affraid I don't understand some important issue here.

Some addional info:

- Netbeans project encoding: UTF-8
- Help->About: 
    *NetBeans IDE 8.1 (Build 201510222201)
    *Java: 1.8.0_92; Java HotSpot(TM) 64-Bit Server VM 25.92-b14
    *System: Windows 7 version 6.1 running on amd64; UTF-8; de_DE (nb)
radekEm
  • 4,617
  • 6
  • 32
  • 45

3 Answers3

1

You properties file in the case 1 is correct.

According to Oracle, properties file are written and read in ISO 8859-1 character encoding. See https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding.

Some developers in my team are using Eclipse, which doesn't always automatically convert properties file to ISO 8859-1. So, errors in displayed characters can occur. We have used a Maven plugin called native2ascii-maven-plugin to convert these files to ISO 8859-1 encoding. See https://github.com/mojohaus/native2ascii-maven-plugin and https://mvnrepository.com/artifact/org.codehaus.mojo/native2ascii-maven-plugin

Other developers are using Netbeans (like me), and Netbeans is fully compliant with Oracle specifications. So Netbeans write properties file in ISO 8859-1 by default.

So, two possibilities :

  • write your properties file in ISO 8859-1 encoding (done automatically with Netbeans).
  • Or, write your properties file in UTF-8 encoding (done by default with Eclipse or Notepad++) and you convert it to ISO 8859-1. Avoid another tools to reconvert ISO 8859-1 to UTF-8 (SVN, GIT, another scripts...).
cactuschibre
  • 1,908
  • 2
  • 18
  • 36
0

It's because of this line (see http://wiki.netbeans.org/FaqI18nProjectEncoding):

*.properties files always use ISO-8859-1 encoding plus \uXXXX escapes. (International characters will be displayed natively in the editor but stored as an escape on disk.)

So it may be forced in ISO-8859-1... Then maybe you're doing it wrong and your .properties file has to be in ISO-8859-1?

Yvan
  • 2,539
  • 26
  • 28
-1

Case 1 : your file is not in UTF-8

Case 2-3, yout file should be in UTF-8, but your app don't manage UTF-8 display.

I'm not using Netbeans (and you are the first user than i meet), but i found this by a simple research :

Go to etc folder in Netbeans home --> open netbeans.conf file and add on netbeans_default_options following line:

-J-Dfile.encoding=UTF-8

Restart Netbeans and it should be in UTF-8

J.Mengelle
  • 341
  • 3
  • 11