Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

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

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

    
What's the encoding of the text? –  Matt Ball Apr 20 '10 at 13:11

2 Answers 2

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.

share|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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.