• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Excel file saved by javamail API not readable to apache poi API

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I receive a file on email which I read using javamail API and save it onto disk directory


Now another program polls that disk directory and reads all incoming file. I am only concerned with File extensions - xls/xlsx, so I use apache poi to read the files:


This sometimes(read random) results in error as below

[2013-07-18 23:38:32,409] ERROR [AvailabilityDirectoryPoller]: Exception in I/O Reading file
java.io.IOException: Your file contains 79 sectors, but the initial DIFAT array at index 1 referenced block # 98. This isn't allowed and your file is corrupt
at org.apache.poi.poifs.storage.BlockAllocationTableReader.<init>(BlockAllocationTableReader.java:103)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)
at com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.process(AvailabilityDirectoryPoller.java:178)
at com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.fileFound(AvailabilityDirectoryPoller.java:73)
at org.sadun.util.polling.DefaultListener.receive(DefaultListener.java:43)
at com.deltax.util.listener.SignalQueue.run(Unknown Source)

If I open the javamail saved file in MS Excel, it opens with no warnings/errors.

Please advice how to handle this one.
Posts: 24654
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And... does this always happen with Excel files sent by e-mail? Or only one particular file? Have you acquired a copy of that file via some other method and compared it to the result of saving it via JavaMail? Are you sure that the polling program waited for your file-saving code to finish before grabbing the file?
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!