Invalid header reading xls file

前端 未结 3 1765
独厮守ぢ
独厮守ぢ 2021-01-12 06:33

I am reading one excel file on my local system. I am using POI jar Version 3.7, but getting error Invalid header signature; read -2300849302551019537 or in Hex 0xE011BDBFEF

3条回答
  •  情深已故
    2021-01-12 07:13

    If your project is maven project, the following code may help:

    /**
     * Get input stream of excel.
     * 

    * Get excel from src dir instead of target dir to avoid causing POI header exception. *

    * @param fileName file in dir PROJECT_PATH/src/test/resources/excel/ , proceeding '/' is not needed. * @return */ private static InputStream getExcelInputStream(String fileName){ InputStream inputStream = null; try{ inputStream = new FileInputStream(getProjectPath() + "/src/test/resources/excel/" + fileName); }catch (URISyntaxException uriE){ uriE.printStackTrace(); }catch (FileNotFoundException fileE){ fileE.printStackTrace(); } return inputStream; } private static String getProjectPath() throws URISyntaxException{ URL url = YourServiceImplTest.class.getResource("/"); Path path = Paths.get(url.toURI()); Path subPath = path.subpath(0, path.getNameCount() -2); return "/" + subPath.toString(); }

提交回复
热议问题