【发布时间】:2015-04-15 10:02:15
【问题描述】:
我有一个包含多行的文本文件。我需要动态编辑这个文本文件。但我想在文本文件的倒数第二行添加动态文本。
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());
}
}
}
现在我需要一些东西来帮助我在倒数第二行添加文本,因为我有总行数
【问题讨论】:
标签: java