資源簡(jiǎn)介
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()) {
// 當(dāng)前行號(hào),從0開(kāi)始
System.out.println("current record: " + cr.getCurrentRecord());
// 本行內(nèi)容
System.out.println("RawRecord:" + cr.getRawRecord());
// 每一列的內(nèi)容
System.out.println("getValues() ");
for (String s : cr.getValues()) {
System.out.print("--" + s);
}
System.out.println();
}
} catch (IOException e) {
// TODO 自動(dòng)生成 catch 塊
e.printStackTrace();
}
}
public void writeCsv(String path,Interview interview) {
try {
String csvFilePath = path;//測(cè)試地址
CsvWriter wr =new CsvWriter(csvFilePath,',',Charset.forName("utf-8"));
String[] contents = {"aaaaa","bbbbb","cccccc","ddddddddd","不知道中文會(huì)不會(huì)亂碼呢"}; //這個(gè)只是測(cè)試數(shù)據(jù),具體要怎么樣的形式保存待定
wr.writeRecord(contents);
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}

代碼片段和文件信息
- 上一篇:java解壓縮文件文件夾
- 下一篇:Jpcap 64位
評(píng)論
共有 條評(píng)論