-3

I have to read .csv file in Java, and then convert it from UTF-8 to iso 8859-1. Any hints ? I know I have to use opencsv library to read file in java, but I have no idea how to do converting. Thanks a lot for all tips.

mavrise
  • 611
  • 1
  • 5
  • 5

1 Answers1

1

I understand, the CSV file is encoded in UTF-8, and you want to output a file in ISO-8859-1.

Java Strings contain the characters, no matter how they came from some whatever-encoded source.

So, it's two steps:

  • The CSV reader must be configured to decode UTF-8. I don't know the library. If it has a Charset constructor parameter or something similar, supply UTF-8 there. If not, you can try setting the system property file.encoding, but be careful, as that affects the whole JVM and not only the CSV reader function.

  • When writing your output file, you must specify it to be written in "ISO-8859-1". Most file-writing classes have a constructor parameter for this.

Of course, ISO-8859-1 only contains a small subset of the complete Unicode. So don't be surprised if the output file either contains strange replacement characters or throws exceptions if the input has characters from e.g. the Greek alphabet.

Ralf Kleberhoff
  • 6,990
  • 1
  • 13
  • 7