Friday, May 15, 2009

Exception Occured :java.io.IOException: Invalid header signature; read ..... , expected ...............



Problem:
This is one of the Common Exceptions which we come across daily in our lives. When i was trying to read a csv (Excel) file in my java code i was not able to read the file. My task was to read the csv file and upate database.

Exception i encountered was:
"Exception Occured :java.io.IOException: Invalid header signature; read 0x6E5F7463656A626F, expected 0xE11AB1A1E011CFD0"

Solution:
If we are using MS Office 2003 we generally face this issue. If we are trying to open a file that contains more than 65,536 rows or 256 columns. To fix this problem, open the source file in a text editor such as Microsoft Word. Save the source file as several smaller files that conform to this row and column limit, and then open the smaller files in Excel.

For example:
We are using MS office 2003 and trying to read a file called testing.csv through java code. Our testing.csv file has 75,000 rows. Since it is crossing 65,536 rows we were facing this issue. so what we can do is create two new csv files with names as testing1.csv file and other as testing2.csv file. Copy first 37,500 rows of testing.csv file and paste them in testing1.csv file and now copy remaining 37,500 rows from testing.csv file and paste them in testing2.csv. Now try to read testing1.csv and testing2.csv file separately in your java code. This process should resolve the exception.

Similar Exceptions:
     - Exception Occured :org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance

2 comments:

  1. Hi Dear,
    i've done this procedure but same error again.

    Regards
    Khalid Rizwan.

    ReplyDelete
  2. Hi Khalid,

    Sorry for the late reply... Can you please let me know what actually you did? You can mail me rahamat_234@yahoo.com for a faster reply.

    Thanks,
    Rahamat.

    ReplyDelete