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

java 读取 CSV 资料

2013-08-16 
java 读取 CSV 文件@Transactional//(rollbackForException.class) LISHUCHAOpublic void readByCSV(File

java 读取 CSV 文件

@Transactional//(rollbackFor=Exception.class) LISHUCHAOpublic void readByCSV(File upload, String FORMNO) throws Exception {InputStreamReader freader = new InputStreamReader(new FileInputStream(upload), "GB2312");CsvListReader reader = new CsvListReader(freader, CsvPreference.EXCEL_PREFERENCE);reader.getCSVHeader(true);// 去除头部字段声明List<String> line = new ArrayList<String>();int i = 1;while ((line = reader.read()) != null) {line.add(FORMNO);line.add("");line.add("");line.add("");line.add("");line.set(10, replaceChar(line.get(10)));System.out.println(line.get(10));line.set(11, replaceChar(line.get(11)));System.out.println(line.get(11));line.set(12, replaceChar(line.get(12)));System.out.println(line.get(12));line.set(13, replaceChar(line.get(13)));System.out.println(line.get(13));line.set(14, replaceChar(line.get(14)));System.out.println(line.get(14));line.set(15, replaceChar(line.get(15)));System.out.println(line.get(15));line.set(16, replaceChar(line.get(16)));System.out.println(line.get(16));jdbcDAO.insertMaterial(line, i);//materialStockedDAO.insertBySql(line, i);System.out.println("---------------------------   " + i + "\t" + line.get(0) + "\t" +line.get(1) + "\t" + line.get(2) + "\t" + line.get(3));i ++;}reader.close();}

?

热点排行