java.lang.System里面有方法
setOut
public static void setOut(PrintStream out)
Reassigns the "standard" output stream.
First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.
Parameters:
out - the new standard output stream
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow reassigning of the standard output stream.
Since:
JDK1.1
See Also:
SecurityManager.checkPermission(java.security.Permission), RuntimePermission--------------------------------------------------------------------------------如果是日志,建议使用apache的log4j可以重定向屏幕输出,而且扩充性也好
setOut
public static void setOut(PrintStream out)
Reassigns the "standard" output stream.
First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.
Parameters:
out - the new standard output stream
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow reassigning of the standard output stream.
Since:
JDK1.1
See Also:
SecurityManager.checkPermission(java.security.Permission), RuntimePermission--------------------------------------------------------------------------------如果是日志,建议使用apache的log4j可以重定向屏幕输出,而且扩充性也好
例如,你可以写一个Errorlog.java
这个类有一个静态的成员函数log,来完成错误记录,向一个log.txt文件中添加信息
那么你就可以在你的程序中用Errorlog.log(String err);来实现你的功能了
private File errfile = new File("d:\\err.log");
PrintWriter out = null;
public ErrLog (String errMsg) {
try {
out = new PrintWriter(new BufferedWriter(new FileWriter(errfile)));
out.println(errMsg);
}
catch (IOException ioe) {//..}
finally {
out.close();
}
}
}