Java IO stream run error, save exception to file inside

Source: Internet
Author: User

Java IO stream

When you run an error, save the exception to the file

Below this instance, after running, enter the number, for the correct, if the input string, then error message, Save the wrong information

//When you run an error, save the exception to the file//below this instance, after running, enter the number, for the correct, if the input string, then error message, Save the wrong informationImportJava.io.*;ImportJava.util.*; Public classindex{ Public Static voidMain (string[] args)throwsexception{Try{            //Create a filePrintStream Zhengque =NewPrintStream ("D:/zhegnque.txt"); PrintStream Cuowu=NewPrintStream ("D:/cuowu.txt"); //using ScannersScanner input =NewScanner (system.in); intShuzi;    System.setout (Zhengque); //If there is no error, save to this fileSystem.seterr (CUOWU);//If there is an error, save to this file, this function is associated with the contents of the following catch                         while(true) {Shuzi=Input.nextint (); System.out.println ("The number entered is:" +Shuzi); }        }        Catch(Exception e) {System.err.println ("Execution Error"); }                            }}

Java IO stream run error, save exception to file inside

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.