-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportManager.java
More file actions
36 lines (32 loc) · 1023 Bytes
/
ExportManager.java
File metadata and controls
36 lines (32 loc) · 1023 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
35
36
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
public class ExportManager {
public static void export(List<Item> list, String request){
File theDir = new File("src/Exports");
if (!theDir.exists()){
theDir.mkdirs();
}
File file = new File("src/Exports/"+ request +".csv");
try{
if(!file.exists()){
file.createNewFile();
}
else{
System.out.println("File " + file.getName() + " already exists");
return;
}
}catch(IOException e){
System.out.println("IOException occurred");
}
try(FileWriter fw = new FileWriter("src/Exports/"+ request +".csv", true)){
for(Item i : list){
fw.write(i.toString());
}
}catch(IOException e){
System.out.println("IOException occurred");
}
System.out.println("Exported");
}
}