import
java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class B ... {
public static void main(String[] args) ...{
try ...{
System.setOut(new PrintStream(new FileOutputStream(new File("c:/test.txt"))));
System.out.println("haha");
} catch (Exception e) ...{
e.printStackTrace();
}
}
}
*******************************************************************************************************************************
System.err和System.out 就是错误输出和标准输出
如果你用LOG4J记录日志的话,且设定错误等级的话
System.err的输出是将记录到日志中
*******************************************************************************************************************************
在你setout之前,把System.out赋值给一个PrintStream对象;如:
PrintStream new = new PrintStream(....);
PrintStream old = System.out;
System.setout( new );
......
.....
System.setout(old); // 这样就恢复到默认输出状态了.
*******************************************************************************************************************************
一个PrintStream 可以被创建为自动刷新的;这意味着当一个字节数组(bytearray)被写入,或者某个println 方法被调用,或者一个换行字符或字节(‘ ‘)被写入之后,PrintStream 类型的flush 方法就会被自动地调用。 // 第一种 System.out.write(b); // 第二种要flush for(int i = 0; i <greetin...
import java.io.FileOutputStream;
import java.io.PrintStream;
public class B ... {
public static void main(String[] args) ...{
try ...{
System.setOut(new PrintStream(new FileOutputStream(new File("c:/test.txt"))));
System.out.println("haha");
} catch (Exception e) ...{
e.printStackTrace();
}
}
}
*******************************************************************************************************************************
System.err和System.out 就是错误输出和标准输出
如果你用LOG4J记录日志的话,且设定错误等级的话
System.err的输出是将记录到日志中
*******************************************************************************************************************************
在你setout之前,把System.out赋值给一个PrintStream对象;如:
PrintStream new = new PrintStream(....);
PrintStream old = System.out;
System.setout( new );
......
.....
System.setout(old); // 这样就恢复到默认输出状态了.
*******************************************************************************************************************************
一个PrintStream 可以被创建为自动刷新的;这意味着当一个字节数组(bytearray)被写入,或者某个println 方法被调用,或者一个换行字符或字节(‘ ‘)被写入之后,PrintStream 类型的flush 方法就会被自动地调用。 // 第一种 System.out.write(b); // 第二种要flush for(int i = 0; i <greetin...