Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > platform default charset

Reply
Thread Tools

platform default charset

 
 
Christophe Darville
Guest
Posts: n/a
 
      08-20-2004
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


 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      08-20-2004
"Christophe Darville" <(E-Mail Removed)> writes:

> 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.
 
Reply With Quote
 
 
 
 
Christophe Darville
Guest
Posts: n/a
 
      08-20-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Christophe Darville" <(E-Mail Removed)> writes:
>
> > 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.



 
Reply With Quote
 
Mark Thornton
Guest
Posts: n/a
 
      08-20-2004
Tor Iver Wilhelmsen wrote:

> "Christophe Darville" <(E-Mail Removed)> writes:
>
>
>>How can I change the platform's default charset used by a VM ?

>
>
> 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
 
Reply With Quote
 
Real Gagnon
Guest
Posts: n/a
 
      08-20-2004
> 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.
--
Real Gagnon from Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
 
Reply With Quote
 
Adam Maass
Guest
Posts: n/a
 
      08-22-2004

"Christophe Darville" <(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
Mark Thornton
Guest
Posts: n/a
 
      08-22-2004
Christophe Darville wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String default encoding: UTF-16 or Platform's default charset? cs_professional Java 14 12-12-2010 06:10 PM
javascript charset <> page charset optimistx Javascript 2 08-15-2008 12:42 PM
platform's default charset ? gk Java 32 03-13-2006 01:57 PM
nio and default charset Stefano Java 1 06-04-2004 09:58 AM
Problem with default Charset Encoding Servlet (Windows vs. RedHat) J.P.Jarolim Java 0 02-27-2004 04:11 PM



Advertisments