platform default charset

  • Thread starter Christophe Darville
  • Start date
C

Christophe Darville

Hello,

How can I change the platform's default charset used by a VM ?

I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.



Thank you,
Christophe
 
T

Tor Iver Wilhelmsen

Christophe Darville said:
How can I change the platform's default charset used by a VM ?

Why would you want to?
I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.

Look a bit more, there is one that takes a charset as parameter.
 
C

Christophe Darville

the getBytes() method was just a sample to explain what charset I was
talking about.

In fact, I want to change the default charset for encoding strings in
general. So, if there is a default charset, I guess there must be a way to
change it

Tor Iver Wilhelmsen said:
Christophe Darville said:
How can I change the platform's default charset used by a VM ?

Why would you want to?
I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.

Look a bit more, there is one that takes a charset as parameter.
 
M

Mark Thornton

Tor said:
Why would you want to?

On Windows, Java usually uses cp-1252, however in the case of a command
line application anything you type will usually have code page 850 (in
western europe) and the output is also expected to be in this character
set. To avoid this mismatch you can either change the codepage of the
command prompt (doesn't work on Windows 9x), or change the default
character set for the JVM. The default character set is given by a
system property (see System.getProperties()), so it might be possible to
override this on the java command line using the -D option. Write a
simple java application to find the correct name for the property and
test if overriding it works (not all system properties can be changed in
this way).

Why Windows has a different default code page for command line
applications and GUI applications is another story.

Mark Thornton
 
R

Real Gagnon

the getBytes() method was just a sample to explain what charset I was
talking about.

In fact, I want to change the default charset for encoding strings in
general. So, if there is a default charset, I guess there must be a
way to change it

The file.encoding property is used by many classes to get the default
encoding (eg. java.io,* and JavaMail). So depending of what is the ultimate
goal it's maybe the answer that you are looking for.

You set it on the command line with something like :

java -Dfile.encoding=Cp850 MyApp

Bye.
 
A

Adam Maass

Christophe Darville said:
Hello,

How can I change the platform's default charset used by a VM ?

I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.

On Solaris operating systems, you can change the value of the LANG
enviroment variable.

-- Adam Maass
 
M

Mark Thornton

Christophe said:
Hello,

How can I change the platform's default charset used by a VM ?

I am talking about the charset used by String methods such
byte[] getBytes()
Encodes this String into a sequence of bytes using the
platform's default charset, storing the result into a new byte array.

In the case of Sun's JVM add a command line argument like this:

java -Dfile.encoding=windows-1252 ...

Mark Thornton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top