How do I set or modify the character encoding for a project?
NetBeans implements a project encoding setting.
To change the language encoding for a project:
- Right-click a project node in the Projects windows and choose Properties.
- Under Sources, select an encoding value from the Encoding drop-down field.
The encoding affects at least:
- how non-ASCII characters are displayed in the editor window when you open files
- Java file compilation of sources containing non-ASCII identifiers, string literals, or comments
- textual search for international characters over the project
You can also specify the encoding that will be used at runtime. For example, this can be useful when the encoding for the operating system on which the application will run is different from your project's encoding.
To specify the encoding to be used at runtime:
- In the Files window for your project, open nbproject > private > private.properties
- Add the following line to the private.properties file and save changes:
This encoding will override the encoding setting for your project and will be used when running your application.
- *.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.)
- *.xml files and some *.html files can specify their own encodings, regardless of the project encoding. For such files, the IDE's editor ignores the project encoding.
Non-ASCII characters may be used in filenames relevant to a project regardless of the project's source file encoding, subject to the capabilities of your operating system. (Modern Linux installations can generally handle any Unicode character in filenames. Other operating systems generally do not handle full Unicode in filenames well, or handle only characters appropriate to the OS's region settings.) If such filenames are referred to in the bodies of source files, however, then the project encoding is relevant; for example, Klíč.java must contain class Klíč in its body, so the project encoding must handle Czech characters.
For a new IDE installation, UTF-8 encoding is the default for new projects, as this encoding can handle any Unicode characters, making it the best choice for most people. When you create a new project, the IDE initially defaults to giving it the same encoding as the last project on which you set the encoding. If you want another encoding, just change it in the properties dialog.
If you change the encoding of a project that already has non-ASCII characters in its source files, those characters may no longer be valid, and compiling or running the project may fail; if those files are opened in the source editor, they may be displayed (and saved) incorrectly.
Applies to: NetBeans 6.8+