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?

link|improve this question
What's the encoding of the text? – Matt Ball Apr 20 '10 at 13:11
feedback

migrated from stackoverflow.com Apr 20 '10 at 13:17

This question came from our site for professional and enthusiast programmers.

2 Answers

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.

link|improve this answer
3  
Try notepadd++ as a free notepad replacement (notepad-plus.sourceforge.net/uk/site.htm). Very handy and knows how to handle encoding properly. Also does syntax highlighting for various languages and XML. – Tom Cabanski Apr 20 '10 at 13:15
or... output the encoding preamble to the file – Lasse V. Karlsen Apr 20 '10 at 13:17
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown