Opencsv CSVWriter using utf-8 doesn't seem to work for multiple languages

I have a very annoying encoding problem using opencsv. When I export the csv file, I set the character type to "UTF-8".

CSVWriter writer = new CSVWriter(new OutputStreamWriter("D:/test.csv", "UTF-8")); 

but when I open the csv file with Microsoft Office Excel 2007, it turns out that it has a UTF-8 BOM encoding ?

As soon as I save the file in Notepad and open it again, the file will return to UTF-8, and all the letters in it will be displayed in order. I think I searched enough, but I did not find a solution to prevent my file from becoming a "UTF-8 Specification." any ideas please?

+7
source share
2 answers

I believe your file is encoded as "UTF-8 without specification." You better give BOM encoding to your file, although in most cases this is not necessary, but only one obvious exception is when you work with ms excel.

 FileOutputStream os = new FileOutputStream(file); os.write(0xef); os.write(0xbb); os.write(0xbf); CSVWriter csvWrite = new CSVWriter(new OutputStreamWriter(os)); 

Now your file will be understood as excel as utf-8 csv.

+13
source

UTF-8 and UTF-8 Signature (which are sometimes incorrectly called UTF-8 BOM ) are the same encodings, and the signature is used only to distinguish it from any other encodings . Any unicode application must correctly handle the UTF-8 signature (which is a sequence of three bytes of EF BB BF ).

Why Java specifically adds this signature and how to stop it, which I do not know.

+2
source

All Articles