我用以下方法生成简单的日志,可是每次新生成的日志都会覆盖旧的日志,如何才能让新生成的日志追加到文件末尾而不覆盖新的日志呢? String str = "abcd";
PrintStream out = new PrintStream("f:/test.txt");
System.setOut(out);
System.out.println(str);
PrintStream out = new PrintStream("f:/test.txt");
System.setOut(out);
System.out.println(str);
改成:PrintStream ps = new PrintStream(new FileOutputStream("f:/test.txt",true));即可!
如:
PrintStream("f:/test.txt");
String s = "ddddddddddddddddd";
PrintStream ps = new PrintStream(new FileOutputStream("f:/test.txt",true));
System.setOut(ps);
System.out.println(s);
遇到这样的问题还是查一下java的帮助文档,这里面什么都有,要学会自己解决自己可以解决的问题,只有这样你才能进步呢