An error is reported when a new excel file is created and written in java poi.
1234567891011121314 |
String filePath = "FILES\\" +filename<span></span>+ ".xls" ; File file = new File(filePath); FileOutputStream out = new FileOutputStream(filePath); // file = new File("filepath location"); FileInputStream fis= new FileInputStream(file.getAbsolutePath()); String[] test = (String [])ExcelInfo.toArray( new String[ 0 ]); // Create an excel file object HSSFWorkbook wb = new HSSFWorkbook(fis); // HSSFWorkbook wb = new HSSFWorkbook(); // Create a table HSSFSheet sheet = wb.getSheetAt( 0 ); |
I first create an excel file, and then run the program to report an error when writing it. The error is as follows:
Java. io. IOException: Unable to read entire header; 0 bytes read; expected 512 bytes
At org. apache. poi. poifs. storage. HeaderBlock. alertShortRead (HeaderBlock. java: 226)
At org. apache. poi. poifs. storage. HeaderBlock. readFirst512 (HeaderBlock. java: 207)
At org. apache. poi. poifs. storage. HeaderBlock. <init> (HeaderBlock. java: 104)
At org. apache. poi. poifs. filesystem. POIFSFileSystem. <init> (POIFSFileSystem. java: 138)
At org. apache. poi. hssf. usermodel. HSSFWorkbook. <init> (HSSFWorkbook. java: 327)
At org. apache. poi. hssf. usermodel. HSSFWorkbook. <init> (HSSFWorkbook. java: 308)
At com. CreateFiles. Excel. write2003Excel (Excel. java: 32)
At com. CreateFiles. FilesCreate. main (FilesCreate. java: 145)
When I write data into Excel using POI in java, the memory overflow occurs. The data volume is about 0.2 million. If you have any better solutions, give the source code,
If it is a one-time write, there is really no good way, try BufferedOutputStream
Java poi is written to excel and cannot be viewed
It is best to check whether the downstream content is closed. debug it. If not, comment out the generated content first, test whether the excel file is correctly generated, and then add the content step by step.