您的位置:首页 > 其它

300.3重定向输出流实现程序日志

2017-09-18 15:35 561 查看
package example3;
import java.io.*;
public class File {

public static void main(String[] args)  {
try {
PrintStream out = System.out;//保留原输出流
PrintStream ps = new PrintStream(new FileOutputStream("log.txt",true));//创建文件输出流
System.setOut(ps);//设置新的输出流

System.out.println("java程序设计");
System.out.println("导出到文件...请查看日志");

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

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: