黑马程序员技术交流社区

标题: 怎样使用PrintSteam呢? [打印本页]

作者: 任亚俊    时间: 2013-12-23 17:01
标题: 怎样使用PrintSteam呢?
本帖最后由 任亚俊 于 2013-12-23 22:06 编辑

我知道可以用PrintSteam打印内容到控制台,但具体怎么实现呢?如下:
  1.                 PrintStream myOut;
  2.                 myOut = new PrintStream("D:\\hello.txt");
  3.                 myOut.println("Hello World!");
复制代码
上面代码把Hello World输出到了hello.txt中,怎样构造PrintSteam对象,才能让Hello World输出到控制台呢?

作者: Kyle    时间: 2013-12-23 17:40
把路径名改成System.out就行了,意思是成为标准的输出流,即控制台输出。

  1. public class Test {

  2.         public static void main(String[] args) throws IOException {
  3.                  PrintStream myOut;
  4.          myOut = new PrintStream(System.out);
  5.          myOut.println("Hello World!");
  6.         }

  7. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2