在Java中,我想将一个字符串写入文件中特定行的末尾。简单的方法:
BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
bw.write(String);
不起作用,因为它总是写在文件末尾。有没有简单的方法?
最佳答案
您必须获取要添加字符串的行号...然后使用 readLine()
迭代该文件.
while (br.readLine() != null) {
if (actualLine == yourLine) // write the String
actualLine ++;
}
关于java - 在java中连续写入一行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31110808/