如何检查并关闭excel文件是否已在java中打开 [英] how to check and close if an excel file is already open in java

查看:386
本文介绍了如何检查并关闭excel文件是否已在java中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Java:检查文件是否已打开





<我正在创建一个swing实用程序,我在其中创建并使用Apache poi的excel表。
如果文件在我尝试访问时已经打开,则会抛出异常,就像其他进程正在使用此excel文件一样。所以我想要的是检查是否已打开excel文件,如果是,则关闭它。

I am making a swing utility in which i am creating and using a excel sheet by Apache poi. If the file is already opened while i m trying to access it it throws an exception like some other process is using this excel file. So all i want is to check if that excel file is already opened and if yes then close it.

推荐答案

你试过这个:

File file = new File(pathToFile);
if (file.canRead()) {
  <do whatever you are doing with the file>
}

这篇关于如何检查并关闭excel文件是否已在java中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆