Ankur
Ankur

Reputation: 12774

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.

enter image description here

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.

Upvotes: 0

Views: 1549

Answers (3)

Esailija
Esailija

Reputation: 140220

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.

Upvotes: 1

Joachim Sauer
Joachim Sauer

Reputation: 308031

In a Windows environment, when an encoding is called "Unicode" then it usually refers to UCS-2 or UTF-16.

Upvotes: 0

Dima Kurilo
Dima Kurilo

Reputation: 2276

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

Upvotes: 0

Related Questions