I need my CSV file name to have a constant name + the exact time and date when file has been created.
For example – constant(my_file) + “_20200411_02:00”
private final CsvFile csvFile;
public static final String CSV_NAME = "file_name";
private List<String> formattedEntries() {
String cvs_separator = ";";
return csvFile.getEntries()
.stream()
.map(v -> v.getRange() + cvs_separator + v.getPersonNumber() + cvs_separator + v.getFieldInput())
.collect(Collectors.toList());
}
public void writeToCsv() {
File csvOutputFile = new File(CSV_NAME);
try (PrintWriter pw = new PrintWriter(csvOutputFile)) {
formattedEntries().forEach(pw::println);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
The code above formatting each object and adding modified object to list, then calling PrintWriter to print the file and as you can see the constant is there but the mission of mine is to have the exact time and date added.
Would appreciate any help
Thank you
Please login or Register to submit your answer