Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IOException Exception Invalid header signature  RSS feed

 
sitereg sam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had written a program using HSSF api to copy a excel sheet to a cvs file. The program works fine as a stand-alone application. I tried to integrate it with an existing code. I got an issue. The following is the code



When i run the application, the execution of the line
HSSFWorkbook srcWb = new HSSFWorkbook(srcFis) reports
IOException Exception Invalid header signature; read 63361219987247567, expected -2226271756974174256

copySheets() methods works fine in the stand-alone application.

It seems some problem occurs while creating InputStream srcFis at "InputStream srcFis = new FileInputStream(fileName)" and
fileName is available and its pointing to the right file.

Kindly help me if anyone experience/knows about the problem..
Thanks in advance...
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!

It seems like everybody suddenly needs to read Excel spread sheets into Java. That doesn't answer your question, but I find it interesting.

Anyway, many file formats start with a magic number. For example Java class files begin with the hex bytes CAFEBABE. More prosaically, XLS files begin with d0 cf 11 e0 a1 b1 1a e1, which taken as a little endian eight byte integer is -2226271756974174256. I thought your problem was you were trying to read a CSV file with a framework that's specifically looking for XLS files. However, the weird thing is you are getting 63361219987247567 which translates to hex as E11AB1A1E011CF, so it looks the header is all right except that you're missing the first byte. It would be interesting to open that file with a hex editor and see if that byte is actually missing or not.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and welcome to the JavaRanch.

Please UseCodeTags when posting code. It will highlight your code making it much easier to read. This time I've added them for you so that you can see the difference.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!