An error is reported when a new excel file is created and written in java poi.

Source: Internet
Author: User

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 = newFile(filePath);               FileOutputStream out = newFileOutputStream(filePath);                //             file = new File("filepath location");                   FileInputStream fis=newFileInputStream(file.getAbsolutePath());                               String[] test = (String [])ExcelInfo.toArray(newString[0]);             // Create an excel file object              HSSFWorkbook wb = newHSSFWorkbook(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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.