Re: How to specify encoding in Java?

From: chris (chris_at_kiffer.eunet.be)
Date: 01/24/04


Date: Sat, 24 Jan 2004 23:32:29 +0100

Konrad Den Ende wrote:

> I've been looking around and i've been given some hints but
> i simply can't get to the bottom of it. How do i specify the
> character encoding for reading text froma file?

Depends a bit on what you mean exactly by "read text from a file"; at some
point you have to convert bytes to chars (either by converting a byte[] to
a String or by wrapping an InputStream in a Reader), and you should find
that the method (or constructor) you used to do that is capable of taking a
parameter which specifies the encoding. If you don't give one then it will
use the default encoding, which IIRC is specified by the system property
"file.encoding"; which in turn probably defaults to "8859_1". If you want
to mix German and Chinese then you frobaly want to use "UTF-8".

Since this is 2004 (not to mention 4702) I am obliged to inform you that
you have much better control over character encoding if you use java.nio.

-- 
Chris Gray      chris@kiffer.eunet.be
/k/ Embedded Java Solutions


Relevant Pages

  • Re: URI without file extension
    ... Andreas Prilop is somewhat extremistic in the issue of declaring the character encoding. ... Using a tag to specify the character encoding, though illogical, is a method approved in the HTML 4.01 specification, and browsers are required to recognize it. ... Andreas is completely right in suggesting that authors should primarily try and find the way to set the real HTTP headers. ...
    (comp.infosystems.www.authoring.html)
  • Re: RSS feeds and HTML special characters
    ... to specify somewhere that the HTML document should be rendered as ... It's an important principle (see RFC2070 for the original ... character which is outside of the chosen character encoding. ... the old MIME terminology uses the attribute name "charset" to specify ...
    (comp.lang.perl.misc)
  • Re: Character encoding
    ... and although I specify ... Character Encoding mismatch! ... The character encoding specified in the HTTP header (utf-8) is ... If you had a decent host, ...
    (alt.html)
  • How to specify encoding in Java?
    ... I've been looking around and i've been given some hints but ... i simply can't get to the bottom of it. ... How do i specify the ... character encoding for reading text froma file? ...
    (comp.lang.java)
  • Character encoding
    ... and although I specify ... when it is opened the character encoding is utf-8 and you have to change it to Greek. ... Where in the http header is the utf-8 specified and how can I change it? ...
    (alt.html)