score:1
this is intended behavior. the propertyresourcebundle
relies on the properties
class, whose load
method always assumes the file to be encoded is iso-latin-1¹:
the input stream is in a simple line-oriented format as specified in load(reader) and is assumed to use the iso 8859-1 character encoding; that is each byte is one latin1 character. characters not in latin1, and certain special characters, are represented in keys and elements using unicode escapes as defined in section 3.3 of the java™ language specification.
so converting your copied characters to unicode escape sequences in the right thing to ensure that they will be loaded properly. at runtime, the resourcebundle
will contain the right character content.
while in eclipse, source files usually inherit the charset setting from their parent, to end up at the project or even system wide setting, it supports setting the charset encoding for single files and conveniently changes it automatically to iso-latin-1 for .properties
files.
note that starting with java 9, you can use utf-8 for properties resource bundles. this does not require additional configuration actions, as the charset encoding is determined by probing. as the documentation of the propertyresourcebundle(inputstream)
constructor states:
this constructor reads the property file in utf-8 by default. if a malformedinputexception or an unmappablecharacterexception occurs on reading the input stream, then the propertyresourcebundle instance resets to the state before the exception, re-reads the input stream in iso-8859-1 and continues reading. if the system property java.util.propertyresourcebundle.encoding is set to either "iso-8859-1" or "utf-8", the input stream is solely read in that encoding, and throws the exception if it encounters an invalid sequence.
this works, as both encodings are identical for ascii characters, while for non-ascii sequences, it practically never happens for real life text that an iso-latin-1 sequence forms a valid utf-8 sequence. this applies to propertyresourcebundle
which handles this probing, not for the properties
class, which still only uses iso-latin-1 in its load(inputstream)
method.
¹ i kept the statement in this absolute form for simplicity, despite, as elaborated at the end of this answer, java 9 has lifted this restriction.
Source: stackoverflow.com
Related Query
- Handling non-english characters using Eclipse
- Delete non utf8 characters in Eclipse using regex
- Eclipse Java Program to read non English characters from System.in
- Using Eclipse with Arabic and English on the same line
- non printable characters in Eclipse junit view
- Handling dependencies of an Eclipse plugin built with Tycho, using a Target Platform
- Printing Unicode characters using Java in eclipse works, but not when I export to a jar
- Search for words with non-ASCI characters in Java ResourceBundles using Eclipse
- Show SOME invisible/whitespace characters in Eclipse
- Multiple contexts with the same path error running web service in Eclipse using Tomcat
- Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory
- Getting "CHECKOUT can only be performed on a version resource" when trying to commit using Eclipse subversive plugin
- Eclipse 3.7 (Indigo) + Tomcat7 --- Cannot create a server using the selected type
- Java "constant string too long" compile error. Only happens using Ant, not when using Eclipse
- Tomcat 6 server creation using eclipse IDE on ubuntu
- How to find usages using Eclipse IDE?
- Replace spaces with tabs using Eclipse
- Eclipse 4.2 (Juno) 'Cannot create a server using the selected type' in Tomcat 7
- Attach debugger to application using Eclipse
- How to see from where a public method is called in Eclipse using Java?
- How do I run Eclipse using Oracle's new 1.7 JDK for the Mac?
- Merging of branch to trunk in SVN using Eclipse
- ClassNotFoundException when using User Libraries in Eclipse build path
- How to debug Java code when using ANT script in Eclipse
- Using Haml & Sass with Eclipse
- Using the Android SDK on a Mac, Eclipse is really slow. How can I speed it up?
- Can Eclipse the Organize Import (ctrl+shift+o) command's handling of static imports be modified?
- Using both Eclipse and NetBeans on the same project
- Eclipse CDT using MinGW does not output in console
- How do I merge a CVS branch into HEAD using the Eclipse merge tools?
More Query from same tag
- Odoo v8 server won't start from eclipse
- Loading Clojure code in Eclipse plug-in
- Android Eclipse issue
- Git repo outside of Eclipse workspace
- WildFly 10.x always getting HTTP error 403: forbidden
- Weblogic slow with Eclipse breakpoints
- Using Eclipse To Study Large Code Base, and Trace Method Calls
- How to open a url's returned content in an eclipse editor?
- Class constructor-arg causes exception
- No data shown on listview
- Eclipse/ADT giving hundreds of errors "resource entry is already defined"
- Eclipse does not recognize any methods of BitmapFactory.Options variable
- Set Video Source From Project in Android Eclipse
- eclipse how to import java types quickly in javadoc comment links?
- nodeclipse only allows debugging of 1 .js file at a time
- What do I need for autocomplete and ctrl+click to work in eclipse after importing a project from Perforce and converting it to a maven project?
- Using Eclipse for Intellij Idea projects
- Cannot create Class of type "JSF Managed Bean" in Eclipse. JavaServer Faces category Missing
- Massive Eclipse AST Java Refactoring
- Android Alert Dialog crashes my application
- Import UML files into Papyrus
- Use Junit or TestNG with the windows shell
- Start another Activity
- I want to add zxing to my project
- Eclipse Project import Error
- Android SQLIte No Such Table Error - On Click
- Compiler wont let String variable in switch statement
- Is it possible to set open resource (ctrl-shift-R) to search full path by default in Eclipse IDE?
- Adding Keyword in Eclipse
- Eclipse code assistance in Java