Reputation: 12774
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.
Upvotes: 0
Views: 1549
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
Reputation: 308031
In a Windows environment, when an encoding is called "Unicode" then it usually refers to UCS-2 or UTF-16.
Upvotes: 0
Reputation: 2276
Try add BOM to first byte of file. http://en.wikipedia.org/wiki/Byte_order_mark
Upvotes: 0