
Hi,
thanks for quick response, I want to insert text at some particular line number..
after line number four my text will display in text file using java program

import java.io.*;
public class WriteAtSpecificLine {
public static void main(String[] args) {
String line = "";
int lineNo;
try {
File f=new File("c:/file.txt");
FileWriter fw = new FileWriter(f,true);
BufferedWriter bw = new BufferedWriter(fw);
LineNumberReader lnr = new LineNumberReader(new FileReader(f));
lnr.setLineNumber(4);
for(int i=1;i<=lnr.getLineNumber();i++){
bw.newLine();
}
bw.write("Hello World");
bw.close();
lnr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.