将.csv文件读入1D数组c#

时间:2017-12-02 00:40:09

标签: c# csv

我想将此代码从java转换为C# 我需要从csv逐行写入并将其存储在数组中吗?

String csvFile = "data.csv";
String line = "";
String cvsSplitBy = ",";
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) 
{

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

 // use comma as separator
 String[] data = line.split(cvsSplitBy);
 System.out.println(Integer.parseInt(data[0]) + "  "+data[1] +  "  "+data[2] );
  }

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

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

如果您尝试将每个记录/行解析为数组,这可能会有所帮助。

dplyr