Re: How to specify encoding in Java?
From: chris (chris_at_kiffer.eunet.be)
Date: 01/24/04
- Next message: mitch: "Re: Mars Rover Not Responding - Update - NASA Makes Contact With Mars Rover"
- Previous message: Matt O'Toole: "Re: So I guess MIT is not good enough anymore?"
- In reply to: Konrad Den Ende: "How to specify encoding in Java?"
- Next in thread: Raymond DeCampo: "Re: How to specify encoding in Java?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: mitch: "Re: Mars Rover Not Responding - Update - NASA Makes Contact With Mars Rover"
- Previous message: Matt O'Toole: "Re: So I guess MIT is not good enough anymore?"
- In reply to: Konrad Den Ende: "How to specify encoding in Java?"
- Next in thread: Raymond DeCampo: "Re: How to specify encoding in Java?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|