Hi guys, ran into a small problem, i can read & write anything i want to a text file as well as append to the end of the line but I cant seem to figure out how to edit a specific line.
Lets say in the text file i have:
xml
java
C
assembly
and i want to edit the text file to change the C, into C++, how would I go about doing this? Ive searched through the internet but couldn't find an answer.
my current code is below which only writes to the end of the file & i would like it to modify the 3rd line, can anyone help me as to what i am doing wrong?
thanks
import java.io.*;
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
try{
FileReader file1 = new FileReader("/Applications/eclipse/Projects/ATM/src/carlos.txt");
BufferedReader f = new BufferedReader(file1);
String temp = null;
int i =0 ;
while((temp=f.readLine()) !=null)
{
i++;
if(i==3)
{
try{
FileWriter file2 = new FileWriter("/Applications/eclipse/Projects/ATM/src/carlos.txt",true);
BufferedWriter file3 = new BufferedWriter(file2);
file3.write("C++");
file3.close();
}
catch(Exception e)
{}
}
}
f.close();
}
catch(Exception e)
{}
}
}