资源介绍
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();
}
}
- 上一篇: 常用无线网卡抓包驱动WinPcap_4_1_2
- 下一篇: 组播测试软件