forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenCSVWriteEx2.java
More file actions
34 lines (26 loc) · 1016 Bytes
/
OpenCSVWriteEx2.java
File metadata and controls
34 lines (26 loc) · 1016 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
30
31
32
33
34
package com.zetcode;
import com.opencsv.CSVWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class OpenCSVWriteEx2 {
public static void main(String[] args) throws IOException {
String[] items1 = {"book", "coin", "pencil"};
String[] items2 = {"pen", "chair", "lamp"};
String[] items3 = {"ball", "bowl", "spectacles"};
List<String[]> entries = new ArrayList<>();
entries.add(items1);
entries.add(items2);
entries.add(items3);
String fileName = "src/main/resources/items.csv";
try (FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter osw = new OutputStreamWriter(fos,
StandardCharsets.UTF_8);
CSVWriter writer = new CSVWriter(osw)) {
writer.writeAll(entries);
}
}
}