Click to See Complete Forum and Search --> : File reading and writing


BuddyKumar
02-13-2006, 04:21 AM
Hi,

I want read a text file and insert some lines in middle of the same text file

Plz Help Me

Khalid Ali
02-13-2006, 12:42 PM
if you write the code and paste it here it will be easy for some one to help you. Unless ofcourse you expect some one to write it for you...:-)

BuddyKumar
02-15-2006, 01:12 AM
Hi
i am trying to insert some Text after line which contains a String as "Node"
it is writing fine but deletes existing Content

wt's wrong with this

File f = new File(args[0]);
RandomAccessFile raf = new RandomAccessFile(f, "rw");
String line = new String();
int count =0;
while((line = raf.readLine())!=null){
if(line.startsWith("Node")){

raf.writeBytes("Text String After Node"+count);
count++;
}
}
raf.close();
} catch (IOException e) {

}