public class ReadCSV {
public static void main(String[] args) {
List<CsvParserPojo> csvParserPojoList = getCsv("C:\\Users\\test\\Desktop\\csv\\Test.csv");
for (CsvParserPojo csvParserPojo:csvParserPojoList){
System.out.println(csvParserPojo);
}
}
private static List<CsvParserPojo> getCsv(String file) {
List<CsvParserPojo> csvParserPojoList = new ArrayList<>();
Path pathToFile = Paths.get(file);
try(BufferedReader br = Files.newBufferedReader(pathToFile)) {
String row = br.readLine();
while (row!=null){
String [] attributes = row.split(".");
CsvParserPojo csvParserPojo = getOneCsv(attributes);
csvParserPojoList.add(csvParserPojo);
}
} catch (IOException e) {
e.printStackTrace();
}
return csvParserPojoList;
}
private static CsvParserPojo getOneCsv(String[] attributes) {
double total_Gain = Double.parseDouble(attributes[0]);
String uid = attributes[1];
double t1 = Double.parseDouble(attributes[2]);
double t2 = Double.parseDouble(attributes[3]);
double t3 = Double.parseDouble(attributes[4]);
double t4 = Double.parseDouble(attributes[5]);
double przep_ywom_v = Double.parseDouble(attributes[6]);
boolean connectionControll = Boolean.parseBoolean(attributes[7]);
CsvParserPojo csvParserPojo = new CsvParserPojo(total_Gain,uid,t1,t2,t3,t4,przep_ywom_v,connectionControll);
return csvParserPojo;
}
}
I have problem with
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.example.ReadCSV.getOneCsv(ReadCSV.java:34)
at org.example.ReadCSV.getCsv(ReadCSV.java:25)
at org.example.ReadCSV.main(ReadCSV.java:13)"