0

大家好,想知道您是否可以帮助我,我正在尝试创建一个日志文件,其中保存了用户选择的所有变量,到目前为止我得到了:

try{
         String content = (" User : " + username + "\n Print job to be printed at : " + (dateFormat.format(cal.getTime())) +"\n Copies selected : " + p +"\n Papersize selected : " + paperSize + "\n Duplex selected : " +duplex + "\n Oreination Selected : " +orienation + "\n Printer Selected : " +printer);

         //File file = new File(log);


         FileWriter fw = new FileWriter(log);
         BufferedWriter bw = new BufferedWriter(fw);
         bw.write(content);
         bw.close();

         System.out.println("Logged the print job");

         } catch (IOException e) {
         e.printStackTrace();
         }

这工作得很好,但是我希望下次调用它来将数据添加到文件中已有的数据下方,而不是覆盖它,这可能吗?因为这比每次创建一个新文件要好得多,

谢谢

4

1 回答 1

3

更改构造函数以使用boolean append和发送true

FileWriter fw = new FileWriter(log, true);

来自FileWriter(File file, boolean append):)

于 2013-02-24T14:49:30.983 回答