forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenCSVReadEx.java
More file actions
29 lines (20 loc) · 736 Bytes
/
OpenCSVReadEx.java
File metadata and controls
29 lines (20 loc) · 736 Bytes
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
package com.zetcode;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class OpenCSVReadEx {
public static void main(String[] args) throws IOException, CsvValidationException {
var fileName = "src/main/resources/numbers.csv";
try (var fr = new FileReader(fileName, StandardCharsets.UTF_8);
var reader = new CSVReader(fr)) {
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
for (var e : nextLine) {
System.out.format("%s ", e);
}
}
}
}
}