文件名称:csv文件读下用的jar包
文件大小:13KB
文件格式:JAR
更新时间:2014-04-18 05:19:17
javacsv
public void readCsv(String path) { try { // 一般,Uses ISO-8859-1 as the Charset. CsvReader cr1 = new CsvReader(path); // 有中文的 CsvReader cr2 = new CsvReader(new FileReader(new File(path))); // 需要指定读入编码的 CsvReader cr = new CsvReader(new InputStreamReader(new FileInputStream(new File(path)),"UTF-8")); while (cr.readRecord()) { // 当前行号,从0开始 System.out.println("current record: " + cr.getCurrentRecord()); // 本行内容 System.out.println("RawRecord:" + cr.getRawRecord()); // 每一列的内容 System.out.println("getValues() "); for (String s : cr.getValues()) { System.out.print("--" + s); } System.out.println(); } } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } public void writeCsv(String path,Interview interview) { try { String csvFilePath = path;//测试地址 CsvWriter wr =new CsvWriter(csvFilePath,',',Charset.forName("utf-8")); String[] contents = {"aaaaa","bbbbb","cccccc","ddddddddd","不知道中文会不会乱码呢"}; //这个只是测试数据,具体要怎么样的形式保存待定 wr.writeRecord(contents); wr.close(); } catch (IOException e) { e.printStackTrace(); } }