-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCSVDataProvider.java
More file actions
49 lines (39 loc) · 1.01 KB
/
CSVDataProvider.java
File metadata and controls
49 lines (39 loc) · 1.01 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.csv;
import com.csvreader.CsvReader;
public class CSVDataProvider {
private static CsvReader reader = null;
private static Object[][] data = null;
private static String getPath(String fileName) {
String path = CSVFileReader.class.getClassLoader().getResource("com/data").getPath();
path = path.replaceAll("bin", "src");
path = path + "/" + fileName;
return path;
}
private static void getData(String fileName) {
int i = 0;
try {
data = new Object[12][4];
reader = new CsvReader(getPath(fileName));
reader.setComment('#');
reader.setUseComments(true);
reader.setSkipEmptyRecords(true);
while(reader.readRecord()){
data[i][0] = reader.get(0);
data[i][1] = reader.get(1);
data[i][2] = reader.get(2);
data[i][3] = reader.get(3);
i++;
}
} catch (Exception e) {
}
}
private static void closeCSV(){
if(reader != null)
reader.close();
}
public static Object[][] getCSVData(String fileName){
getData(fileName);
closeCSV();
return data;
}
}