I recently changed the hosting for my website (from Linux to Linux) and
now I'm experiencing some trouble with java.io.FileReader and
java.io.FileWriter: their getEncoding() method returns ASCII (returned
ISO8859_1 on the previuos host). I've set -Dfile.encoding=ISO-8859-1 but
nothing has changed, except that
javax.mail.internet.MimeUtility.getDefaultJavaCharset() effectively
returns ISO-8859-1.
Does anyone know how the default encoding is selected? I report some
system properties:
file.encoding.pkg: sun.io
user.country: US
java.runtime.version: 1.4.2_04-b05
os.version: 2.4.27
user.timezone: America/New_York
file.encoding: ISO-8859-1
user.language: en
java.version: 1.4.2_04
java.vendor: Sun Microsystems Inc.
-----
Mario
> Hi,
>
> I recently changed the hosting for my website (from Linux to Linux) and
> now I'm experiencing some trouble with java.io.FileReader and
> java.io.FileWriter: their getEncoding() method returns ASCII (returned
> ISO8859_1 on the previuos host). I've set -Dfile.encoding=ISO-8859-1 but
> nothing has changed,
IMHO the pitfall is that you have to use "ISO8859-1"!
> except that
> javax.mail.internet.MimeUtility.getDefaultJavaCharset() effectively
> returns ISO-8859-1.
Don't mix up character encoding and file encoding - char encoding is a
different story.
Matthias
The right name is ISO-8859-1 (see
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html).
I tried anyway (with ISO8859-1 and ISO8859_1) but it doesn't work.
I admit I'm a bit confused in general. By the way the file.encoding
property shouldn't be a solution at all, since it wasn't set on my
previous hosting (and everything was fine). On this one, nothing changes
if I set it or not.
> Don't mix up character encoding and file encoding - char encoding is a
> different story.
FileReader/Writer javadocs talk about "default character encoding".
javax.mail.internet.MimeUtility.getDefaultJavaCharset() gets the
system's default locale and returns the corresponding default Java charset.
When reading a file (written in bytes), Java needs to know which charset
to use to convert 8-bit to 16-bit, and I need to know how the default
one is picked up.
As an alternative, you can specify the encoding explicitly in InputStreamReader,
which is the preferred way.
I always do it, but the problem is still there with software written by
others.
Mario
Then your only hope is to get -Dfile.encoding to work, because if the
conversion is done wrongly, it's not necessarily reversible.