I have a java code that reads an excel file and writes it to a text file. When i get the output text file, I can see only symbols like this in the notepad. "‷搮ㄱ〱〰〠〰〠〰〠〰〠〰〠〰〠〰〠〰〠〰〠〰〠〰〠" But if i open the text file in wordpad or ms-word, the data is correctly displayed. What could be the error?
migrated from stackoverflow.com Apr 20 '10 at 13:17
This question came from our site for professional and enthusiast programmers.
The error lies in using Notepad. Notepad uses the first couple bytes of a file to decide what the encoding is, you have to open a file with a specific encoding to read it properly.
Here's a link to learn ya: http://blogs.msdn.com/oldnewthing/archive/2007/04/17/2158334.aspx
Lesson learned: Don't use notepad.
It's quite likely that the first part of your data looks superficially like Unicode in a certain encoding (UTF-16). This has been a problem in past versions of Windows and can be read about in this article. However, I think since Windows Vista that particular issue was fixed.
A simple workaround would be not to use Notepad for that data.