zoukankan      html  css  js  c++  java
  • 重定向标准流

    重定向标准流

        重定向标准流
           

                 

        下载源代码


        〖 作者:站长整理 〗〖 大小:1k 〗〖 发布日期:2005-08-04 〗〖 浏览:145 〗



         import java.io.*;





        public class Redirect

        {

            public static void main (String args[])

            {

        InputStream origIn = System.in;

        PrintStream origOut = System.out;

        PrintStream origErr = System.err;



        InputStream stdin = null;

        try

            {

            stdin = new FileInputStream ("Redirect.in");

            }

        catch (Exception e)

            {

            System.exit (1);

            }    

        // Create a new output stream for the standard output.

        PrintStream stdout = null;

        try

            {

            stdout = new PrintStream (

        new FileOutputStream ("Redirect.out"));

            }

        catch (Exception e)

            {

            // Sigh.  Couldn't open the file.

            System.exit (1);

            }



        // Create new output stream for the standard error output.

        PrintStream stderr = null;

        try

            {

            stderr = new PrintStream (

        new FileOutputStream ("Redirect.err"));

            }

        catch (Exception e)

            {

            // Sigh.  Couldn't open the file.

            System.exit (1);

            }



                origOut.println ("\n11111111");

                System.out.println ("22222222222222");

                origOut.println ("333333");

                System.err.println ("4444444444444444444");

                origErr.println ("55555555555555");



        // Set the System out and err streams to use our replacements.

        System.setIn ( stdin );//重定向标准输入流

        System.setOut ( stdout );//重定向标准输出流

        System.setErr ( stderr );//重定向错误流



                origOut.println ("\666666666666666666");

                System.out.println ("aaaaaaaaaaaaaa");

                origOut.println ("777777777777");

                System.err.println ("bbbbbbbbbbbbb");

                origErr.println ("99999999999999999999999");



        // Read some input and dump it to the console.

                origOut.println ("\n11111111111111111111111");

        int inChar = 0;

        while (-1 != inChar)

            {

            try

        {

        inChar = System.in.read();

        }

            catch (Exception e)

        {

        // Clean up the output and bail.

        origOut.print ("\n");

        break;

        }

            origOut.write (inChar);

            }



        // Close the streams.

        try

            {

            stdin.close ();

            stdout.close ();

            stderr.close ();

            }

        catch (Exception e)

            {

            origOut.println ("Redirect:  Unable to close files!");

            System.exit (1);

            }



        System.exit (0);

            }

        }

  • 相关阅读:
    模拟登陆江西理工大学教务系统
    python3爬虫 -----华东交大校园新闻爬取与数据分析
    以selenium模拟登陆12306
    PAT (Basic Level) Practice (中文)1076 Wifi密码 (15 分)
    PAT (Basic Level) Practice (中文)1047 编程团体赛 (20 分)
    PAT (Basic Level) Practice (中文)1029 旧键盘 (20 分)
    PAT (Basic Level) Practice (中文)1016 部分A+B (15 分)
    PAT (Basic Level) Practice (中文)1031 查验身份证 (15 分)
    PAT (Basic Level) Practice (中文)1041 考试座位号 (15 分)
    PAT (Basic Level) Practice (中文)1037 在霍格沃茨找零钱 (20 分)
  • 原文地址:https://www.cnblogs.com/lexus/p/2370381.html
Copyright © 2011-2022 走看看