forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenCSVReadEx2.java
More file actions
41 lines (31 loc) · 1.12 KB
/
OpenCSVReadEx2.java
File metadata and controls
41 lines (31 loc) · 1.12 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
package com.zetcode;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class OpenCSVReadEx2 {
public static void main(String[] args) throws IOException {
String fileName = "src/main/resources/numbers.csv";
Path myPath = Paths.get(fileName);
CSVParser parser = new CSVParserBuilder().withSeparator('|').build();
try (BufferedReader br = Files.newBufferedReader(myPath,
StandardCharsets.UTF_8);
CSVReader reader = new CSVReaderBuilder(br).withCSVParser(parser)
.build()) {
List<String[]> rows = reader.readAll();
for (String[] row : rows) {
for (String e : row) {
System.out.format("%s ", e);
}
System.out.println();
}
}
}
}