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可以重定向屏幕输出,而且扩充性也好

解决方案 »

  1.   

    你可以自定义一个类,来向日志文件添加数据,这个类可以用和文件有关的输出流来实现
    例如,你可以写一个Errorlog.java
    这个类有一个静态的成员函数log,来完成错误记录,向一个log.txt文件中添加信息
    那么你就可以在你的程序中用Errorlog.log(String err);来实现你的功能了
      

  2.   

    import java.io.*;class ErrLog {
      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();
        }
      }
    }
      

  3.   

    现在是这样,我定义的流也是PrintWriter类型,但是看到System.seterr(...)后面的类型是PrintStream类型的,有什么办法把握得PrintWrite换为PrintStream么?    也许我的想法不对,printwriter和PrintStream也许就不是一个范畴的东西,请教!