0

I made a project where I write some stuff in a csv file, but special characters don't work correctly, for example characters such as : à, é, ï..
So I changed my code, so that the fileWriter would be encoded in ISO-8859-1.

OutputStreamWriter o = new OutputStreamWriter(new FileOutputStream(file), "ISO-8859-1");
writer = new CSVWriter(o, ';', CSVWriter.DEFAULT_QUOTE_CHARACTER,
                CSVWriter.DEFAULT_ESCAPE_CHARACTER,
                CSVWriter.DEFAULT_LINE_END); 

Most of the characters work, but the characters ', doesn't work correctly, it's shown as a ?.

Perhaps, I need to change encoding, but CSV is supposed to use ISO-8859-1.
Do you have any suggestion?

Hamza Ince
  • 604
  • 17
  • 46
  • 2
    Some characters simply aren't in the ISO-8859-1 charset. So if you can't use UTF-8 then you can't write these characters. You could either discard them or [normalize your text](https://stackoverflow.com/questions/3322152/is-there-a-way-to-get-rid-of-accents-and-convert-a-whole-string-to-regular-lette). – Sascha May 16 '19 at 12:59
  • Thank you, @Sascha for your answer, I was planning on doing that, as I wrote in the edited version of the question, the character was not in ISO-8859-1, so I will replace every occurence of it. – Hamza Ince May 16 '19 at 13:03
  • I suggest that, rather than hacking your data, just use [UTF-8](https://en.wikipedia.org/wiki/UTF-8) encoding. – Basil Bourque Jul 03 '19 at 22:31
  • @Sascha I suggest you make an Answer of your Comment so that it can be accepted, and this Question can be marked as resolved. – Basil Bourque Jul 03 '19 at 22:32

2 Answers2

0

I just found out, that it was not a ' but a , I should escape it, so that every will become a '.
You need to be more careful when you handle a file.

Hamza Ince
  • 604
  • 17
  • 46
  • Use **"Windows-1252"** (Windows Latin-1) instead of **"ISO-8859-1"** (Latin-1). This deals with comma-like quotes too. – Joop Eggen Jul 04 '19 at 11:04
0

Some characters simply aren't in the ISO-8859-1 charset. So if you can't use UTF-8 then you can't write these characters. You could either discard them or normalize your text.

Sascha
  • 1,320
  • 10
  • 16