redirectout.java
来自「疯狂Java讲义_源码(含Java设计模式CHM」· Java 代码 · 共 40 行
JAVA
40 行
import java.io.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class RedirectOut
{
public static void main(String[] args)
{
PrintStream ps = null;
try
{
ps = new PrintStream(new FileOutputStream("out.txt"));
//将标准输出重定向到ps输出流
System.setOut(ps);
//向标准输出输出一个字符串
System.out.println("普通字符串");
//向标准输出输出一个对象
System.out.println(new RedirectOut());
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (ps != null)
{
ps.close();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?