-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExportCSV.java
148 lines (112 loc) · 4.61 KB
/
ExportCSV.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mas_1_10;
/** @author endryys*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class ExportCSV {
public void CreatefileCSV(String filepath, String delim,String[] pcc_initial, String[] pcc_final, String[] p_batt ){
final String NEXT_LINE = "\n";
int i=0;
String pcc_initial_str,pcc_final_str,p_batt_str=new String();
try {
FileWriter fw = new FileWriter(filepath);
/*fw.append("pcc_initial").append(NEXT_LINE);
for(i=0; i<29;i++){
fw.append(Float.toString(pcc_initial[i])).append(NEXT_LINE);
}*/
fw.append("pcc_initial;p_batt;pcc_final\n");
for(i=0; i<47;i++){
if(i==26){
i=26;
}
//pcc_initial_str=Float.toString(pcc_initial[i]);
pcc_initial_str=pcc_initial[i];
pcc_final_str=pcc_final[i];
p_batt_str=p_batt[i];
fw.append(pcc_initial_str+";"+p_batt_str+";"+pcc_final_str+"\n");
}
/*fw.append("testing").append(delim);
fw.append("123").append(NEXT_LINE);
fw.append("value1");
fw.append(delim);
fw.append("312");
fw.append(NEXT_LINE);
fw.append("anotherthing,888\n");*/
fw.flush();
fw.close();
} catch (IOException e) {
// Error al crear el archivo, por ejemplo, el archivo
// está actualmente abierto.
e.printStackTrace();
}
}
//public void CreatefileCSVBATT(String filepath, String delim,float[] p_batt, float[] soc_batt){
public void CreatefileCSVBATT(String filepath, String delim,String[] p_batt, String[] soc_batt){
final String NEXT_LINE = "\n";
int i=0;
String p_batt_str,soc_batt_str=new String();
try {
FileWriter fw = new FileWriter(filepath);
/*fw.append("pcc_initial").append(NEXT_LINE);
for(i=0; i<29;i++){
fw.append(Float.toString(pcc_initial[i])).append(NEXT_LINE);
}*/
fw.append("p_batt;soc\n");
for(i=0; i<47;i++){
p_batt_str=p_batt[i];
soc_batt_str=soc_batt[i];
/*p_batt_str=Float.toString(p_batt[i]);
soc_batt_str=Float.toString(soc_batt[i]);*/
fw.append(p_batt_str+";"+ soc_batt_str+"\n");
}
/*fw.append("testing").append(delim);
fw.append("123").append(NEXT_LINE);
fw.append("value1");
fw.append(delim);
fw.append("312");
fw.append(NEXT_LINE);
fw.append("anotherthing,888\n");*/
fw.flush();
fw.close();
} catch (IOException e) {
// Error al crear el archivo, por ejemplo, el archivo
// está actualmente abierto.
e.printStackTrace();
}
}
/* public static void main(String[] args) {
List<usuario> usuarios = new ArrayList<usuario>();
usuarios.add(new Usuario("1001","Jose","Ramirez Torres","jramirez89@hotmail.com"));
usuarios.add(new Usuario("1002","Saul","Gaviria Garcia","sgaviria12@gmail.com"));
usuarios.add(new Usuario("1003","Maria","Torres Mendoza","mtorres12@yahoo.com"));
String outputFile = "test/usuarios_export.csv";
boolean alreadyExists = new File(outputFile).exists();
if(alreadyExists){
File ficheroUsuarios = new File(outputFile);
ficheroUsuarios.delete();
}
try {
CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');
csvOutput.write("Codigo");
csvOutput.write("Nombres");
csvOutput.write("Apellidos");
csvOutput.write("Correo");
csvOutput.endRecord();
for(Usuario us : usuarios){
csvOutput.write(us.getCodigo());
csvOutput.write(us.getNombres());
csvOutput.write(us.getApellidos());
csvOutput.write(us.getCorreo());
csvOutput.endRecord();
}
csvOutput.close();
} catch (IOException e) {
e.printStackTrace();
}
} */
}