The company originally in the Import Execel file, is an import; that is, each import file should have corresponding Java code to achieve, so in the reading Execel file when there is no problem, these two days, ready to waste the previous practice, unified encapsulation, To be able to parse all the Execel files and return the results as long as the configuration file is available.
In the implementation process, just started with the demo, so the Execel file is a full path (similar to C://test/xxx.xls), parsing time need to open the same Execel file two times, but there will be no problem. Later migrated to the project, because it was imported directly through the Web page, can only get its inputstream stream, can not get its absolute path. Due to the need to use the InputStream two times, it appeared unable to read entire header; 0 bytes Read; Expected bytes such a problem.
Search on the internet for a long time, a lot of solutions are not, and then think of inputstrem flow can only use once, the second failure, only to cause the above problems. There are two ways to solve this, (refer to http://simpleframework.net/bbs/835/27640.html), and I choose to first save this inputstrem stream with a byte number, Use the Bytearrayinputstream package (refer to http://hiok.blog.sohu.com/65555266.html) as follows:
In the beginning, the stream object is saved with a byte number
byte[] buf = Org.apache.commons.io.IOUtils.toByteArray (execelis)//execelis to InputStream stream
/////////////////////////
///InputStream in the place where you need to use the InputStream
bytearrayinputstream Bytearrayinputstream = new Bytearrayinputstream (BUF);
Workbook wb = new Hssfworkbook (bytearrayinputstream);//bytearrayinputstream inherited InputStream, so it's no problem
/// Other places to use are the same principle
//Master: If you only need to use a inputstream flow, you don't need to do this, just use the OK