java - how to read a file line by line and append some string each line? -


i want open file , read line line. in lines want append string line. possible?

i have code opening file , reading following:

file file = new file("myfile.txt"); bufferedreader bufrdr = new bufferedreader(new filereader(file));  string line = null;  try {     while((line = bufrdr.readline()) != null)     {         // read line line , append string line      } } catch (ioexception e) {     // ... } 

but how can append string current line , write file?

as reading file line line. append text line , write other file. example file different name , later can rename file.

just

try {    while((line = bufrdr.readline()) != null)     {     // read line line , append string line     //pseudo code     newline = line + "yourtext";     outputstreamtootherfile.write(newline);      } }  

i think there no way can read , write same file concurrently, holds read/write locks.

thanks


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -