-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvUtil.java
More file actions
31 lines (29 loc) · 1.06 KB
/
Copy pathCsvUtil.java
File metadata and controls
31 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ericzz.utils;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author zz_huns
* @version Id: CsvUtil.java, v 0.1 2019/9/23 12:32 AM zz_huns Exp $$
*/
public class CsvUtil {
public static List<String[]> getTestData(String fileName) throws IOException {
List<String[]> records = new ArrayList<>();
String record;
try (BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));) {
//跳过表头所在的行
file.readLine();
// 遍历数据行并存储在名为records的ArrayList中,每一行records中存储的对象为一个String数组
while ((record = file.readLine()) != null) {
String[] fields = record.split(",");
records.add(fields);
}
} catch (Exception e) {
e.printStackTrace();
}
return records;
}
}