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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -