[英]Saving Excel file takes much time
我正在嘗試打開一個Excel文件,在其中寫一些東西然后保存。 我的問題是保存部分(workbook.write)需要很多時間。 那是我的代碼:
FileInputStream file = new FileInputStream(f2);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheet("Tabelle1");
//Some clonesheet, createrows, createcells, setting style & value
//about 2 sheets ,10 rows * 10 cells
workbook.write(new FileOutputStream(path)); //takes about 2 minutes
workbook.close();
我正在無法在JVM上進行任何修改的生產機器上執行代碼。 我知道堆內存很小。 (我無法打開大於2mb的Excel文件)我不知道這是否與我的問題有關。
謝謝
使用緩沖區而不是直接字段路徑,例如:
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = is.read(buffer))) {
fos.write(buffer, 0, n);
}
或遵循文檔 :
如果流是網絡驅動器上的FileOutputStream或與每個寫入的字節相關聯的高成本/延遲,請考慮將OutputStream包裝在BufferedOutputStream中以提高寫入性能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.