HSSFWorkbook wb =new HSSFWorkbook(fs);时报
OutOfMemoryError: Java heap space
我上传excel后台读取时报这个错误,文件大概7m,是不是文件太大了,请教各位大神应该怎么解决
/**
* 读取Excel的内容,第一维数组存储的是一行中格列的值,二维数组存储的是多少个行
* @param file 读取数据的源Excel
* @param ignoreRows 读取数据忽略的行数,比喻行头不需要读入 忽略的行数为1
* @return 读出的Excel中数据的内容
* @throws
FileNotFoundException
* @throws
IOException
*/
public String clmldrUpload(File file) {
List<String[]> result = new ArrayList<String[]>();
int rowSize = 0;
BufferedInputStream in = null;
// 打开HSSFWorkbook
POIFSFileSystem fs = null;
HSSFWorkbook wb = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
fs = new POIFSFileSystem(in);
wb = new HSSFWorkbook(fs);//这一步的时候出错!!!!
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
HSSFCell cell = null;
int sheetIndex = 0;
HSSFSheet st = wb.getSheetAt(sheetIndex);
// 第一行为标题,不取
for (int rowIndex = 1; rowIndex <= st.getLastRowNum(); rowIndex++) {
HSSFRow row = st.getRow(rowIndex);
if (row == null) {
continue;
}
int tempRowSize = row.getLastCellNum() + 1;
if (tempRowSize > rowSize) {
rowSize = tempRowSize;
}
String[] values = new String[rowSize];
Arrays.fill(values, "");
boolean hasValue = false;
for (short columnIndex = 0; columnIndex <= row.getLastCellNum(); columnIndex++) {
String value = "";
cell = row.getCell(columnIndex);
if (cell != null) {
// 注意:一定要设成这个,否则可能会出现乱码
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
if (date != null) {
value = new SimpleDateFormat("yyyy-MM-dd")