In my case I used this way:
System.setProperty("file.encoding", "UTF-8");
Would it be the language ID used?
In my case I used this way:
System.setProperty("file.encoding", "UTF-8");
Would it be the language ID used?
When you run a program, you "start" a JVM instance and this instance has its own environment variables, some properties being natively initialized (native method initProperties
). In the implementation of System
you notice that there is a static Properties
, which is the object that contains all the properties of system and is accessible by any application / library running on the instance of JVM
.
From the documentation for System.setProperty
Sets the system property indicated by the specified key.
That is, this method creates or changes the value of a system property that is shared by all applications / libraries running on the same instance of JVM
.
In your case you are resetting the default encoding to be used by the applications / libraries running in the same instance that you are running your application.
Just as a curiosity about coding in the JVM, there are three standard "encodings":
file.encoding
: System.getProperty("file.encoding")
;
java.nio.charset.Charset
: Charset.defaultCharset()
. This, at startup of the default encoding, uses the file.encoding
property and if it does not exist, it adopts UTF-8
;
and the encoding of InputStreamReader
: InputStreamReader.getEncoding()
.