platform default charset

Discussion in 'Java' started by Christophe Darville, Aug 20, 2004.

  1. 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
     
    Christophe Darville, Aug 20, 2004
    #1
    1. Advertising

  2. "Christophe Darville" <> 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.
     
    Tor Iver Wilhelmsen, Aug 20, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > "Christophe Darville" <> 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.
     
    Christophe Darville, Aug 20, 2004
    #3
  4. Tor Iver Wilhelmsen wrote:

    > "Christophe Darville" <> 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
     
    Mark Thornton, Aug 20, 2004
    #4
  5. Christophe Darville

    Real Gagnon Guest

    > 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
     
    Real Gagnon, Aug 20, 2004
    #5
  6. Christophe Darville

    Adam Maass Guest

    "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.
    >
    >


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

    -- Adam Maass
     
    Adam Maass, Aug 22, 2004
    #6
  7. 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
     
    Mark Thornton, Aug 22, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J.P.Jarolim
    Replies:
    0
    Views:
    1,055
    J.P.Jarolim
    Feb 27, 2004
  2. Stefano

    nio and default charset

    Stefano, Jun 4, 2004, in forum: Java
    Replies:
    1
    Views:
    478
    Gordon Beaton
    Jun 4, 2004
  3. gk
    Replies:
    32
    Views:
    12,414
    Piotr Kobzda
    Mar 13, 2006
  4. cs_professional
    Replies:
    14
    Views:
    5,274
    cs_professional
    Dec 12, 2010
  5. optimistx

    javascript charset <> page charset

    optimistx, Aug 14, 2008, in forum: Javascript
    Replies:
    2
    Views:
    279
    optimistx
    Aug 15, 2008
Loading...

Share This Page