• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checking that an excel file is already opened by another application

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the following code to check if an excel file is aready open by another app:-



When the file is already open, the following error is generated which I successfully catch and handle:-




All is fine. I shut the excel spreadsheet manually then run my application again. At the point where testOut.close() is executed, above - the file content is erased completely and I am left with a 0k file!

Please would someone be able to tell me where I am going wrong?

many thanks

Clare
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FileOutputStream, in fact all Streams and Readers, by default open a file for writing (or overwriting, if it exists). What you want to do is open the file for appending. Have a look at the javadoc and you'll find the appropriate constructor.
 
Clare McLennan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid I already tried that using the following code:



Problem is that this does not generate an error in the same way as the original code does. I want to check the file is open so I can close it. I am updating existing rows in the spreadsheet. The only thing that works is when the file is not opened by other users, and the FileOutputStream is opened using only the filename in the constructor. Appending the file (regardless of whether it is already open or closed) does not work. I'm looking for an elegant way of checking it is open before I attempt to write to it.
reply
    Bookmark Topic Watch Topic
  • New Topic