Here is my use case ,
I'm reading my input file file.in as an object then converting it as a String
0000001HL26110650059147 TEST- TEST
0000002HL34110FON202212217835294783529 20221221123000 650059147
0000003HL34120FON20221221783529BLE50000395 13626142
0000004HL34120FON20221221783529BLE50000395 13626143
Here is my positions (0-7 : it's a sequence ) , (11-14 : it's my section) and the important one is (47-67 : it's the Oldvalue that i want to change in one condition if section is equals to 120)
For that ,i have to take the Oldvalue from postion 47-67 and check in database using simple query
select NewValue from myTable where Oldvalue = 'Oldvalue'
Then put the NewValue in the place of the Oldvalue in my String
So my output would be :
0000001HL26110650059147 TEST- TEST
0000002HL34110FON202212217835294783529 20221221123000 650059147
0000003HL34120FON20221221783529BLE50000395 NewValue1
0000004HL34120FON20221221783529BLE50000395 NewValue2
Note that the other sections will remain unchanged just the section equals 120 and there is multiple lines where section equals 120
Any idea how to do this please
Here is my attemp but could not continue to find solution ,
try {
File file = new File("C:/Users/20230309.in");
Scanner scanner = new Scanner(file);
List<String> lines = new ArrayList<>();
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lines.add(line);
}
scanner.close();
System.out.println(lines);
for (String element : lines) {
if (element.length()>11 && "120".equals(element.trim().substring(11, 14)))
{
String oldValue = element.substring(47, 67);
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found.");
e.printStackTrace();
}