Hi all,

Is it possible to change a single line in a text file?
The text document looks like this:
Example1 : 12 : 1
Example2 : 13 : 2
Example3 : 16 : 45

So for example I want to change the 2nd line too Example2 : 13 : 83.

This is the current coding I’ve got only it’s pretty useless at it will increment the last element only once and append the text document

public static void IncrementDays(String ID, boolean daystozero){
BufferedWriter bw;
BufferedReader br;
try{
bw = new BufferedWriter(new FileWriter("txtDB.txt", true));
br = new BufferedReader(new FileReader("txtDB.txt"));
String str;
while((str = br.readLine()) != null){
System.out.println("fffff");
if(str.contains(ID) == true){
String[] temp = str.split(":");
String Car_Reg = temp[1];
int x = Integer.parseInt(temp[2]);
if(daystozero == false)
bw.append(ID + " : " + Car_Reg + " : " + ++x);
else
bw.append(ID + " : " + Car_Reg + " : " + 0);
}
}
bw.close();
br.close();
}catch(Exception e){
System.out.println("Error : " + e);
}
}


Many Thanks

Edward Francis