public class CsvFileUtil {
public static List<String[]> readCsvFile(String fileName){
List<String[]> res = new ArrayList<>();
String csvSplitBy = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(fileName));//换成你的文件名
//reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));//固定编码读
String line = null;
while((line=reader.readLine())!=null){
String item[] = line.split(csvSplitBy );//CSV格式文件为逗号分隔符文件,这里根据逗号切分 ,可能存在双引号,里面存在逗号的处理,同表达式解决
res.add(item);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(reader!=null){
try {
reader.close();
reader=null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
return res;
}