I want read my log file and put into csv file via Java. How would I parse the log file with these delimiters into csv file as below.
.log file:
2022-06-01 11:00:00 wt.nm=aa&wt.ti=t1&
2022-06-02 12:00:00 wt.nm=ab&wt.ti=t2&
2022-06-03 10:00:00 wt.nm=ac&wt.ti=t3&
date and time is separated by space, name and title separated by wt.nm=/wt.ti with & as end
CSV output:
date,time,name,title
2022-06-01,11:00:00,aa,t1
2022-06-02,12:00:00,ab,t2
2022-06-03,10:00:00,ac,t3
import java.io.*;
public class test {
public static void main(String[] args) {
try{
BufferedReader in = new BufferedReader(new FileReader("/Users/ts/Desktop/test/src/0606.log"));
FileWriter wb = new FileWriter("/Users/ts/Desktop/testcsv.csv");
String str;
while((str=in.readLine()) != null) {
System.out.println(str);
wb.write(str);
}
}
catch (IOException e) {
}
}
}