简体   繁体   中英

java.io.IOException: Permission denied in jenkins While Closing XSSFWorkbook

I am scrapping data from different websites and i am using apache poi to read and write data in excel.

I am facing permission denied in writeWorkbook.close() method (writeWorkbook is object of XSSFWorkbook).

what am i doing is 1) Reading data from website 2) write it to particular excel sheet 3) close file output stream 4) closing XSSFWorkbook object. in 4th step i am getting error of permission denied.

This whole scenario is running from jenkins through jar file. Jenkins has all permission to file and also directory.

so what and where i am wrong.

Thank you

How exactly are you using your excel file with XSSFWorkbook?

Once you finish writing to XSSFWorkbook, then all you need is to close the OPCPackage object. You don't need to close the file.

// XSSFWorkbook, File
  OPCPackage pkg = OPCPackage.open(new File("file.xlsx"));
  XSSFWorkbook wb = new XSSFWorkbook(pkg);
  ....
  pkg.close();

The docs state that:

Once you have finished working with the Workbook, you should close the package by calling POIXMLDocument.close(), to avoid leaving file handles open.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM