重定向控制台System.out.println输出到文件,再重定向回控制台
来源:互联网 发布:话剧暗恋桃花源知乎 编辑:程序博客网 时间:2024/04/27 18:02
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class Test {
publicstaticvoid main(String[] args) {
PrintStream printStream = null;
PrintStream sysout = System.out;
PrintStream syserr = System.err;
try {
File file = new File("c:\\systemout.log");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
printStream = new PrintStream(new FileOutputStream(new File(
"c:\\systemout.log"),true));
// set output to file instead of console
System.setOut(printStream);
System.setErr(printStream);
System.out.println("Before Redirect:System.out.println");
System.err.println("Before Redirect:System.err.println");
} catch (FileNotFoundException e) {
//TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (printStream !=null) {
printStream.close();
}
// Reset the output to console
System.setOut(sysout);
System.setErr(syserr);
System.out.println("After Redirect:System.out.println");
System.err.println("After Redirect:System.err.println");
}
}
}
- 重定向控制台System.out.println输出到文件,再重定向回控制台
- eclipse控制台输出重定向到文件
- system.out.println重定向
- 控制台输出重定向到Memo
- eclipse控制台输出重定向到…
- MFC控制台指令的重定向输出到文件方法
- eclipse控制台输出重定向
- JAVA-System.out.println之重定向
- 重定向System.out 到文件
- System.out 重定向到文件
- mfc重定向到控制台
- 控制台输入输出重定向
- 控制台输出重定向到MFC的view对象里
- C++在Win32中重定向输出数据到控制台
- Createprocess控制台程序输出重定向
- MFC:Debug控制台重定向输出
- Createprocess控制台程序输出重定向
- 控制台应用程序的输出流重定向
- 博客新开
- LCD驱动程序——代码编写(二)
- 修改数据库表字段长度
- URL特殊符号的处理
- 浏览——用户自定义路径
- 重定向控制台System.out.println输出到文件,再重定向回控制台
- 关于mac binutils
- hdu 1394(有空了用树状数组试试)
- hdu 2205 又见回文
- performSelectorOnMainThread 对参数的引用计数
- Linux查看进程打开多少文件描述符命令-lsof
- PHP底层工作原理
- http://acm.hdu.edu.cn/showproblem.php?pid=3791&&二叉搜索树
- 网络访问消息: 无法显示此页