package com.company.project.utils;
import java.io.*;
import java.util.Map;
/**
* 读取csv
*/
public class ReadCsv {
/*
* java读取.csv文件里面的所有内容
*/
public static void main(String[] args) {
String csvFile = "E:\\data\\CSV_20211229153432.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ","; //csv每行数据的间隔方式,这里是逗号,有的是| 竖线
Map<String, String> row1;
int i = 0;
try {
// in = new BufferedReader(new FileReader(csvFile));
DataInputStream in = new DataInputStream(new FileInputStream(new File(csvFile)));
br = new BufferedReader(new InputStreamReader(in, "GBK"));
while ((line = br.readLine()) != null) {
// user中:位置名称,经度,纬度,区域(城市、农村)
String[] country = line.split(cvsSplitBy);
for (int j = 0; j < country.length; j++) {
System.out.print(country[j]+"=");
}
System.out.println();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
java读取csv
于 2021-12-29 15:54:27 首次发布