如何检查并关闭excel文件是否已在java中打开
问题描述:
可能重复:
Java:检查文件是否已打开
如果文件在我尝试访问时已经打开,则会抛出异常,就像其他进程正在使用此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>
}