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
Post a Comment