redirectiondemo.java

来自「java编程代码」· Java 代码 · 共 35 行

JAVA
35
字号

import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

public class RedirectionDemo
{
   public static void main(String[] args)
   {
      PrintStream errStream = null;
      try
      {
          errStream = 
               new PrintStream(
                       new FileOutputStream("errormessages.txt"));
      }
      catch(FileNotFoundException e)
      {
         System.out.println(
                  "Error opening file with FileOutputStream.");
         System.exit(0);
      }

      System.setErr(errStream);

      System.err.println("Hello from System.err.");
      System.out.println("Hello from System.out.");
      System.err.println("Hello again from System.err.");

      errStream.close( );
   }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?