我有一个文本文件,其中有多行内容。我需要动态地编辑这个文本文件,但我想在文本文件的倒数第二行添加动态文本。
class FileAppending
{
public static void main(String args[]) {
try{
OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream("file path\\x.txt", true), "UTF-8");
int lines = 0;
while (br.readLine != 0){
lines++; // by this i'll get exact line number
}
BufferedWriter fbw = new BufferedWriter(writer);
fbw.write("append txt...");
fbw.newLine();
fbw.close();
}catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
现在我需要一个工具,能够帮助我在倒数第二行添加文本,因为我已经知道总共有多少行。