Thanks a lot for your help.
Use an InputStreamReader/Writer with an
appropriate Charset.
> Thanks a lot for your help.
No worries.
--
Andrew Thompson
http://pscode.org/
The Java String class will do this.
String s = new String( bytes, "UTF-8" );
where "bytes" is a byte[] of the raw UTF-8 codepoints. Convert the
variable s to ISO-8859 with
byte[] winCode = s.getBytes( "ISO-8859-1" );
"winCode" now contains Latin1 codepoints. You may have to check those
exact charset names, I didn't compile those lines.
<http://java.sun.com/javase/6/docs/api/java/nio/charset/Charset.html>
Andrew's suggestion to use InputStreamReader/OuputStreamWriter seems
good too, if you are dealing with streams.
InputStreamReader in = new InputStreamReader( is, "UTF-8" );
will read a UTF-8 formatted InputStream "is" to Java's own internal
String format. OutputStreamWriter is similar.
Java's *internal* format is always the same. Java doesn't deal with
other codepoints directly, just as arrays of bytes (i.e., arrays of
data). You'll always have to go to Java's internal format first, then
to whichever output you want, asfaik.
>Any java code out there to do a similar job as the one iconv does ?
>iconv -f UTF-8 -t ISO-8859-1 -o output.csv input.csv
see http://mindprod.com/applet/fileio.html
read the entire file into String then write it out.
If the file is too big, see http://mindprod.com/products1.html#HUNKIO
see http://mindprod.com/jgloss/encoding.html
for background.
You can also do it with the native2ascii utility.
--
Roedy Green Canadian Mind Products
http://mindprod.com
PM Steven Harper is fixated on the costs of implementing Kyoto, estimated as high as 1% of GDP.
However, he refuses to consider the costs of not implementing Kyoto which the
famous economist Nicholas Stern estimated at 5 to 20% of GDP
Thanks again.
Khalil FOUNDY
You can also ask the FileIO Amanuensis to generate you some code to
read/write in any encoding.
see http://mindprod.com/applet/fileio.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
I advocate that super programmers who can juggle vastly more complex balls than average guys can, should be banned, by management, from dragging the average crowd into system complexity zones where the whole team will start to drown.
~ Jan V.