I have a text file that comes as a parameter to one of my Java methods. First I go through the text file line by line in search of the Emission Date:
If you find it, I extract the date of that line in a variable. As always it is the same, I know that if you find it, I have to do a substring (84,93) to get the date inside a variable and then make a replace () for a new date!
The issue is that the replace () is not going well and does not change the date! I leave my code for you to see:
public class DateFormater {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// Open the file
FileInputStream fstream = new FileInputStream("/home/incentivate/Desktop/AC0121.TXT");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
if(strLine.contains("Fecha de Emision: ")){
String date = strLine.substring(84,93);
if(date.equals("6/08/2018")){
System.out.println("OK");
strLine.replace(date, "06/08/2018"); // regex / cosa a reemplazar
System.out.println(strLine);
}
}
}
//Close the input stream
br.close();
}
In the second if it enters well because it prints the "OK", but when I print the line (strLine) to see if it did the replace () I see that it did not. That could be happening ?
Basically what I need is to put a 0 (zero) in front of the date that comes in the text file.
Example: If the date comes like this: 6/08/2018 I need it to look like this: 06/08/2018