-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportCSV.java
More file actions
33 lines (29 loc) · 998 Bytes
/
ExportCSV.java
File metadata and controls
33 lines (29 loc) · 998 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
package data;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class ExportCSV {
public void exportCSV(String[][] data, String[] columnName) {
try {
FileWriter fw = new FileWriter("fic.csv");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
StringBuilder sb = new StringBuilder();
for (String s : columnName) {
sb.append(String.format("\"%s\",", s));
}
pw.println(sb);
for (String[] datum : data) {
sb = new StringBuilder();
for (int j = 0; j < data[0].length; j++) {
sb.append(String.format("\"%s\",", datum[j]));
}
pw.println(sb);
}
pw.close();
} catch (IOException ex) {
System.err.println("Erreur sur le fichier");
}
}
}