I want to get String data after date in an object
Sample Input:
2019-06-06 13:01:53.263Z|abc|alfkdjas|alfjdlaksd|alkjdfs
2019-06-06 13:01:53.264Z|lkjsfadfi|sadofuoif
2019-04-01 16:47:25.327Z|ERROR 7816
Output: [{"date":"2019-06-06 13:01:53.263Z","data":"|abc| ldskjf "},{"date":"2019-06-06 13:01:53.264Z","data":"|lkjsfadfi"}]
Means i want the data after the first date until second date has come..
I tried to seperate data between two dates..
public static String ReadData() {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(logfilename));
String line = reader.readLine();
JSONArray jason=new JSONArray();
JSONObject jo=new JSONObject();
int count=0;
while (true) {
if(line != null) {
if(count>0) {
}
if(isValidDate(line.split("\\|")[0])) {
count++;
jo.put("date", line.split("\\|")[0]);
jo.put("data",line);
}
line = reader.readLine();
}else {
break;
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
This function seperate my dates from the string...
public static boolean isValidDate(String inDate) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss.ms");
try {
dateFormat.parse(inDate);
} catch (ParseException pe) {
return false;
}
return true;
}
Input:
2019-06-06 13:01:53.263Z|abc| ldskjf
2019-06-06 13:01:53.264Z|lkjsfadfi
Output:
[{"date":"2019-06-06 13:01:53.263Z","data":"|abc| ldskjf "},{"date":"2019-06-06 13:01:53.264Z","data":"|lkjsfadfi"}]
I have a big size of log file here, and from that log file I want to convert that log file to a JSON array.