5

There are Norwegian characters in properties file. When i open in UTF-8 enabled Notepad++ it appears correctly:

Foreslåtte 

But when i open same file in my Netbeans editor; it shows distorted characters like :

Foreslåtte

Netbeans Version in Use: 8.0.2.

Project Type: Maven Project

In Maven Proeject properties there is setting for UTF-8:

<properties>
    <app.navn>posten</app.navn>
    <jdk.version>1.8</jdk.version>
    <wro4j.version>1.7.6</wro4j.version>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <--
    <servlet.version>3.1.0</servlet.version>
</properties>

Could anyone help in finding what settings need to be done in Netbeans to get correct UTF-8 characters?

Madhan
  • 5,750
  • 4
  • 28
  • 61
fatherazrael
  • 5,511
  • 16
  • 71
  • 155
  • I don't know netbeans specifically, but there are two possibilities here. 1 is that the file isn't actually encoded in UTF-8, or two, Netbeans is using your "platform default" encoding, which isn't UTF-8 for some reason. Have you validated that it actually is a valid UTF-8 file? – Daniel Jun 23 '15 at 05:17
  • @Daniel How to validate that? It is simple properties file having values in Key Value format; which contains Norwegian characters. It is getting opening in Notepad++ perfectly. How can i make Netbeans not to use platform default encoding any settings? – fatherazrael Jun 23 '15 at 05:21
  • Like I said I don't know netbeans. Notepad++ may not be loading it as UTF-8, it may have detected some other encoding. – Daniel Jun 23 '15 at 05:22
  • See here: http://stackoverflow.com/questions/4133195/how-to-change-file-encoding-in-netbeans – Arek Jun 23 '15 at 05:22
  • If it's in a java file we can do that but for files like txt,properties it id diffiocult i guess – Madhan Jun 23 '15 at 05:25
  • @Daniel: I have already done few settings in Notepad++. That are to go into Settings -> Preferences -> New Document -> UTF-8 Selected. After these settings are done; when i edit properties file in Notepad++, it by default opens with proper Norwegian characters. Otherwise if i remove those settings then it picks default "Encoding in ANSI" and damage characters. – fatherazrael Jun 23 '15 at 05:30
  • @Ajan Thanks. Will try that. System restart is required for that as Netbeans is already opened and i am not allowed to do changes in file. – fatherazrael Jun 23 '15 at 05:31
  • @Madhan How can we do it for Java files? The settings must be same for both i think as it will reflect in netbeans project? – fatherazrael Jun 23 '15 at 05:31
  • @fatherazrael Go to Project Properties-Sources Category Tab->change Encoding from UTF-8 to windows 1252 – Madhan Jun 23 '15 at 05:48
  • @Madhan It does not work – fatherazrael Jun 23 '15 at 06:45
  • @Ajan I have done changes to .conf file as suggested in your link and it does not work. – fatherazrael Jun 23 '15 at 06:47

3 Answers3

8

Right Click Properties File -> Properties -> Encoding -> Tick Use Project Encoding

Now open the file and matter resolved.

Note: My Project Encoding was already set to UTF-8. You can set i: Right Click on Project -> Properties -> Sources -> Select Encoding UTF-8

fatherazrael
  • 5,511
  • 16
  • 71
  • 155
2

If you open netbeans folder, edit the netbeans.conf (It's inside the etc folder), you might need to open the editor with administrator rights first.
Add -J-Dfile.encoding=UTF-8 to the netbeans_default_options.
Restart netbeans, and it's now opening them correctly.

Anders Metnik
  • 6,096
  • 7
  • 40
  • 79
  • 1
    Thank you a lot! I often open files in NB that isn't in any project. I have struggled with this, searched in menus etc. But this works. – 244an Mar 20 '23 at 12:22
1

Before Java 9, the encoding of a .properties file is ISO-8859-1, also known as Latin-1. All non-ASCII characters must be entered by using Unicode escape characters, e.g. \uHHHH where HHHH is a hexadecimal index of the character in the Unicode character set.

Source: https://en.m.wikipedia.org/wiki/.properties

Further read : https://www.google.com/search?q=java+properties+ascii

xerx593
  • 12,237
  • 5
  • 33
  • 64