首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

jxl读取excel急需关闭Workbook

2012-10-26 
jxl读取excel需要关闭Workbook?/** * 简单的读取excel * @param inputFile * @param inputFileSheetIndex

jxl读取excel需要关闭Workbook?

/** * 简单的读取excel * @param inputFile * @param inputFileSheetIndex * @throws Exception */public static ArrayList<String> sampleReadExcel(File inputFile, int inputFileSheetIndex) throws Exception {ArrayList<String> list = new ArrayList<String>();Workbook book = null;Cell cell = null;//避免乱码的设置WorkbookSettings setting = new WorkbookSettings(); java.util.Locale locale = new java.util.Locale("zh","CN"); setting.setLocale(locale);setting.setEncoding("ISO-8859-1");book = Workbook.getWorkbook(inputFile, setting);Sheet sheet = book.getSheet(inputFileSheetIndex);for (int rowIndex = 0; rowIndex < sheet.getRows(); rowIndex++) {// Excel第一行为表头,因此J初值设为1for (int colIndex = 0; colIndex < sheet.getColumns(); colIndex++) {// 只需从Excel中取出2列cell = sheet.getCell(colIndex, rowIndex);list.add(cell.getContents());}}//【问题:如果在实际部署的时候没有写下面这句是否会导致不断消耗掉服务器的内存?jxl里面有个ReadWrite.java没有关闭读的,只关闭了写的】book.close();return list;}
1 楼 jiyanliang 2008-04-23   它会把所有数据都读到内存中,如果数据量太大的时候,就肯定暴了
看看你调用它的代码。

热点排行