-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (44 loc) · 1.5 KB
/
LogData.yml
File metadata and controls
56 lines (44 loc) · 1.5 KB
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
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.io.BufferedReader;
public class LoggerApp {
public static void main(String[] args) {
// Creates a CSV File with current Year and Month
String fileName = new SimpleDateFormat("MM-yyyy'.csv'").format(new Date());
// Proof of File exist and read the file
File f = new File(fileName);
if (f.exists() && !f.isDirectory()) {
FileReader fr = null;
try {
fr = new FileReader(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr);
} else {
String fileName1 = new SimpleDateFormat("MM-yyyy'.csv'").format(new Date());
}
FileWriter writer;
File datei = new File(fileName);
// LocalDateTime currentDateTime = LocalDateTime.now();
try {
LocalDateTime currentDateTime = LocalDateTime.now();
// System.out.println("Before formatting: " + currentDateTime);
writer = new FileWriter(datei);
// writer.write(currentDateTime.toString());
DateTimeFormatter changeDateTimeFormat = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
writer.write(System.getProperty("line.separator"));
String formattedDate = changeDateTimeFormat.format(currentDateTime);
writer.write(formattedDate);
writer.flush();
writer.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}