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
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();
}