简体   繁体   中英

What is Java's equivalent of Windows Notepad “Unicode Encoding”?

I have tab-separated values which I need to export as a text file using Java, to be opened in Microsoft Excel. The problem arises when the tab-separated values have Chinese characters.

I tried exporting the text file using UTF-8 but Excel is not able to interpret the characters. Then I opened the exported text file in Notepad and saved it as "Unicode" and it started showing the correct charters in Excel.

在此处输入图片说明

So can someone tell me what is the Notepad "Unicode" equivalent in Java?

My code is:

response.getOutputStream().write(reportHTML.getBytes("UTF-8"));

Where reportHTML has tab-separated values.

This is the text file with encoding as Unicode.

That means "UTF-16LE" , and every java platform implementation is required to support it.

response.getOutputStream().write(reportHTML.getBytes("UTF-16LE"));

The notepad unicode encoding also inserts the UTF-16LE BOM FF FE at the start of the file.

Try add BOM to first byte of file. http://en.wikipedia.org/wiki/Byte_order_mark

在Windows环境中,当编码称为“ Unicode”时,它通常是指UCS-2或UTF-16

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM