Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POI- Log file to xlsx -writing data in unreadable format and i think this is due to wrong encodeing

 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

When I am trying to read data from BufferedReader and writing into excel using FileOutputStream object with POI APIs then i am getting the data in excel file in bad formats. you can check the log file and excel file attached for more information.

Here my problem is I cannot use BufferedWriter in place of FileOutputStream because POI class XSSFWorkbook only have one write method and we can only pass FileOutputStream class objet there.

Please have a look the code and suggest me how i can proceed further.

xslx file output.JPG
[Thumbnail for xslx file output.JPG]
output file data
logfiledata.JPG
[Thumbnail for logfiledata.JPG]
input file data
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I would fix is the name of the file encoding - there is no "UTF8", it's called "UTF-8".

The obvious thing to do would be to print out the values of "lineData" to check whether they are what you think they are.
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf - that was very silly mistake but now I have modify my code and have another problem:

Do you have any idea why getEncoding() method giving me UTF8 instead of UTF-8?

I am using eclipse and i think my old code is calling now. do you know how to fix this?

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any idea why getEncoding() method giving me UTF8 instead of UTF-8?

I don't. The java.nio.charset.Charset javadocs make it clear which charsets need to be supported. I did a quick grep through the Java source code, and it looks like some parts of it may accept "UTF8" instead of "UTF-8" (the XML parser, for example, although that may be required by the XML spec), but not all of it. And in particular, probably not the java.io package.
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW UTF-16 is working for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic