我无法弄清楚为什么以下代码导致在执行到达第73行时捕获列出的错误:
public static Workbook createWorkBook(InputStream fsin)
{
if(! fsin.markSupported()) {
fsin = new PushbackInputStream(fsin, 8);
}
try
{
if(POIFSFileSystem.hasPOIFSHeader(fsin)) { //Line 73
return new HSSFWorkbook(fsin);
}
} catch (IOException ex) {
Logger.getLogger(UpdateExcel.class.getName()).log(Level.SEVERE, null, ex);
}
这些是错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.io.PushbackInputStream.unread(PushbackInputStream.java:235)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.hasPOIFSHeader(NPOIFSFileSystem.java:378)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.hasPOIFSHeader(POIFSFileSystem.java:133)
at movavg.UpdateExcel.createWorkBook(UpdateExcel.java:73)
at movavg.UpdateExcel.initialize(UpdateExcel.java:109)
at movavg.text.TestAnalysis.main(TestAnalysis.java:54)
我尝试过流式传输xls和xlsx文件,结果总是一样的。