poi解析excel时问题

try {
				//2007+
				workbook = new XSSFWorkbook(path + "\\" + fileName);
			} catch (IOException e1) {
				//2003
				workbook = new HSSFWorkbook(new FileInputStream(path + "\\" + fileName));
			}

 代码先贴出来

运行报错

Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'D:\demo.xls'
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
	at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:62)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:167)
	at com.beyondsoft.local.LocalString.readExcel(LocalString.java:26)
	at com.beyondsoft.local.LocalString.main(LocalString.java:98)

 使用HSSF处理2003,XSSF处理2007,怎么检查都感觉没有问题啊

仔细读每一行的代码才发现catch语句中顺手写了IOException,太粗心了,果断改成Exception,问题解决

你可能感兴趣的:(java,poi)