我想打开一个文件,然后逐行读取。在某些行中,我想将一个字符串附加到这一行。这可能吗?
我有一个用于打开文件并读取它的代码,如下所示:
File file = new File("MyFile.txt");
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
try {
while((line = bufRdr.readLine()) != null)
{
// read line by line and append some string to the line
}
} catch (IOException e) {
// ...
}
但是如何将字符串附加到当前行并将其写入文件?