Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • 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
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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 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.filesystem.POIFSFileSystem.<init>(
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(
at org.sadun.util.polling.DefaultListener.receive(
at 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?
We're all out of roofs. But we still have tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!