JAVA POI关闭Workbook
POI操作中,最近遇到了没有关闭Workbook而导致无法删除对应的文件,以下是关闭的方法。
jar包:poi-3.8.jar
File f = new File("/path/to/excel/file");
Workbook wb = null;
NPOIFSFileSystem npoifs = null;
OPCPackage pkg = null;
try {
npoifs = new NPOIFSFileSystem(f);
wb = WorkbookFactory.create(npoifs);
} catch(OfficeXmlFileException ofe) {
pkg = OPCPackage.open(f);
wb = WorkbookFactory.create(pkg);
}
if (npoifs != null) { npoifs.close(); }
if (pkg != null) { pkg.close(); }

浙公网安备 33010602011771号