11.2

java读取csv文件

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class CSVReader {

public static void main(String[] args) {

String csvFile = "/Users/mkyong/csv/country.csv";
String line = "";
String cvsSplitBy = ",";

try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {

while ((line = br.readLine()) != null) {

// use comma as separator
String[] country = line.split(cvsSplitBy);

System.out.println("Country [code= " + country[4] + " , name=" + country[5] + "]");

}

} catch (IOException e) {
e.printStackTrace();
}

}

}

posted @ 2021-11-02 20:46  {hunter}ZY  阅读(46)  评论(0编辑  收藏  举报