There is a java class in which the elements of their time and date are recorded in the map. Something like this:
new Map <String,String>() .put("time1","2015-01-25T03:01:00") We need a method that will find the old date (before (now)), and change it to a new one (literally 2.3 days ahead)
I will welcome any advice.
At first I tried to just download the file and change the data: (there is a lot of unnecessary in the code, but it works)
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import java.util.ArrayList; import java.util.List; import java.io.BufferedWriter; public class FileReplace { List<String> lines = new ArrayList<String>(); String line = null; public void doIt() { try { File f1 = new File("TFile.java"); FileReader fr = new FileReader(f1); BufferedReader br = new BufferedReader(fr); while ((line = br.readLine()) != null) { if (line.contains("2015-01-25T03:01:00")) line = line.replace("2015-01-25T03:01:00", "2016-01-06T08:01:00 "); lines.add(line); } fr.close(); br.close(); FileWriter fw = new FileWriter(f1); BufferedWriter out = new BufferedWriter(fw); for(String s : lines) out.write(s); out.flush(); out.close(); } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String args[]) { FileReplace fr = new FileReplace(); fr.doIt(); } } Then I think like comparing dates, something like this: (only sketches)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date1 = sdf; // Date date2 = ; data from the file if (date1.after(date2)) { date2 = data2.replace() // some random future data } I can not reduce everything to a heap, and I still need to get the time and date from the file, but as I wrote at the beginning, itβs written like this.
new Map <String,String>() .put("time1","2015-01-25T03:01:00")