package com.haoran.test;
import java.io.FileNotFoundException;
import java.io.PrintStream;
/**
*
* @author haora
*描述:将程序运行相关信息记录到日志中
* 生命是彩色的!
*
*/
public class javatest6 {
public static void main(String[] args) {
PrintStream out = System.out;
try {
PrintStream ps = new PrintStream(“./log.txt”);
System.setOut(ps); //先把输出流定向到日志
System.out.println(“——————————————————————————————————————————”);
System.out.println(“本程序运行正常,无报错”);
System.out.println(“——————————————————————————————————————————”);
System.setOut(out); //再将标准输出重定向控制面板
System.out.println(“写入日志正常”);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println(“写入日志失败,请开发人员检查代码异常!错误码:001”);
}
}
}