java对于需要在50多个excel文件上运行并且每个文件平均包含25k行的项目,最佳的方法是什么
对于需要操作50多个excel文件且每个文件平均包含25k行的项目,最佳方法是什么
项目说明: 我必须加载数据(每个文件中有3列)并将它们存储在数组中,然后将它们用于不同的计算。我正在使用poi库处理excel文件。当我尝试加载数据时,出现了一个错误:线程“main”java中出现异常。lang.OutOfMemoryError:超出GC开销限制
让我知道避免GC开销错误的方法
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
public class Main {
Date date;
static int temp = 0;
static ArrayList<User> userlist = new ArrayList<User>();
public static void main(String[] args) throws EncryptedDocumentException, InvalidFormatException, IOException, ParseException {
File f = new File("C:\\Users\\Shiva\\Downloads\\ISEC\\IS");
System.out.println(f.list().length);
int count = 0;
for (File file : f.listFiles()) {
if (file.isFile()) {
count++;
userlist.add(new User());
String SAMPLE_XLSX_FILE_PATH = file.getAbsolutePath();
Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
Sheet sheet = workbook.getSheetAt(0);
int[] oct = new int[sheet.getLastRowNum()];
int[] dur = new int[sheet.getLastRowNum()];
long[] frstrealpt = new long[sheet.getLastRowNum()];
Iterator<Row> rowIterator = sheet.rowIterator();
int z = 0;
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
if (row.getRowNum() == 0) {
continue; //just skip the rows if row number is 0
}
Cell pkts = row.getCell(2);
Cell octets = row.getCell(3);
oct[z] = (int) octets.getNumericCellValue();
Cell duration = row.getCell(9);
dur[z] = (int) duration.getNumericCellValue();
Cell realfrstpkt = row.getCell(6);
frstrealpt[z] = (long) realfrstpkt.getNumericCellValue();
z++;
}
System.out.println(oct.length);
}
}
System.out.println(userlist.size());
}
}
共 (0) 个答案