我正在制作一个 madlib 程序,该程序打开一个 txt 文件,然后向用户询问数据,然后呈现一个最终的 madlib,它完美地显示在控制台中,但只有 madlib 的最后一行出现在文本文件中,请在 Java 中提供帮助。
FileWriter outFile = new FileWriter(name + ".txt");
BufferedWriter bf = new BufferedWriter(outFile);
long start = System.nanoTime();
content = JOptionPane.showInputDialog("Please enter a/n " +
m.group().subSequence(1,m.group().length()-1));
madlib = m.replaceFirst(content);
System.out.println(madlib);
bf.write(madlib);
long elapsedTime = System.nanoTime() - start;
elapsedTime=elapsedTime/1000000;
System.out.println(m.group().subSequence(1,m.group().length()-1) + " ; " +
content + " ; " + elapsedTime +"ms");
bf.write(m.group().subSequence(1,m.group().length()-1) + " ; " + content +
" ; " + elapsedTime +"ms");
bf.close();