import java.io.*;
public class MainClass
{
public static void main(String args[])
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
try{
File f = new File("Test.txt");
RandomAccessFile raf = new RandomAccessFile(f,"rw");
String s = raf.readLine();
s = raf.readLine();
System.out.println(s);
System.out.println("new?");
String newStr = br.readLine();
int l = s.length();
System.out.println("length: " + l);
for(int i=1; i<=l; i++)
{
raf.writeBytes("\b");
}
raf.writeBytes(newStr);
}
catch(Exception e){
}
}
}
This is just a practice program. It is meant to replace the second line with a new record. But instead of backspacing "\b" it overwrites the third line and when it writes "newStr" it also overwrites.
This is totally not what I'm trying to get. I want to remove the second line by backspacing it and then insert a new
string in its place without touching the third line.
How do I do this?