将 System.out 转换成 PrintWriter
来源:互联网 发布:德州理工大学 知乎 编辑:程序博客网 时间:2024/05/22 14:39
System.out 是一个 PrintStream,而 PrintStream 是一个 OutputStream.。
PrintWriter 有一个可以接受 OutputStreamSystem 作为参数的构造器。因此,只要我们
需要,就可以使用那个构造器把 System.out 转换成 PrintWriter。
//: c12:ChangeSystemOut.java
// Turn System.out into a PrintWriter.
import com.bruceeckel.simpletest.*;
import java.io.*;
public class ChangeSystemOut {
private static Test monitor = new Test();
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out, true);
out.println("Hello, world");
monitor.expect(new String[] {
"Hello, world"
});
}
PrintWriter 有一个可以接受 OutputStreamSystem 作为参数的构造器。因此,只要我们
需要,就可以使用那个构造器把 System.out 转换成 PrintWriter。
//: c12:ChangeSystemOut.java
// Turn System.out into a PrintWriter.
import com.bruceeckel.simpletest.*;
import java.io.*;
public class ChangeSystemOut {
private static Test monitor = new Test();
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out, true);
out.println("Hello, world");
monitor.expect(new String[] {
"Hello, world"
});
}
} ///:~
- 将 System.out 转换成 PrintWriter
- 使用PrintWriter(System.out)没有数据输出到控制台上的问题
- 使用标准输出流(system.out)和打印流 (PrintWriter)来读取txt文件
- 将System.Drawing.Bitmap转换成System.Drawing.Imaging.BitmapSource
- 内置对象out和PrintWriter
- Java 将System.out和System.err重定向
- 将字符串转换成System.Drawing.Color类型
- 将字符串转换成System.Drawing.Color类型
- C#将字符串转换成System.Drawing.Color类型
- System.out
- System.out
- 将System.out.println()打印的内容输出到文件
- System.out.println将内容输出到文件保存
- PrintWriter out=response.getWriter()的问题
- PrintWriter out = response.getWriter();乱码解决
- PrintWriter out=response.getWriter()的问题
- PrintWriter out = response.getWriter()使用
- 将 System::String 转换为标准字符串
- 冒泡排序
- 备忘:使用无线连接adb调试
- 如何估算PGA,SGA的大小,配置数据库服务器的内存
- 动态可重构
- Android图片处理(Matrix,ColorMatrix)
- 将 System.out 转换成 PrintWriter
- NSSortDescriptor(数组排序)
- readyState五中状态详解
- 五招加速网页响应时间(2/2)
- 标准 I/O 重定向
- tsm ANS0326E问题处理
- [Redis] redis-cli 命令总结
- shell运算、双括号、双中括号
- c++ 虚析构函数