I am downloading a single excel file from a browser. I am using a POI jar. But get an invalid header signature error; read 3255307777713450285, expected -2226271756974174256
below are the two jsp files that I used: JSP 1:
<form action="Upload.jsp" enctype="MULTIPART/FORM-DATA" method=post > <input type="file" name="filename" /> <input type="submit" value="Upload" /> </form>
JSP 2: Upload.jsp
try{ InputStream file = request.getInputStream(); POIFSFileSystem myFileSystem = new POIFSFileSystem(file); HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem); HSSFSheet mySheet = myWorkBook.getSheetAt(0); Iterator rowIter = mySheet.rowIterator(); rowIter.next(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator cellIter = myRow.cellIterator(); cellIter.next(); System.out.println(((HSSFCell)cellIter.next()).toString()); } }catch(Exception ex){ System.out.println(ex.getMessage()); }
But getting an error in the line POIFSFileSystem myFileSystem = new POIFSFileSystem (file);
How to solve this problem?
source share