Java Self-study note-Basic syntax 3setOut () method to set a new output stream

Source: Internet
Author: User

1  PackageHahaa;2 3 Importjava.io.FileNotFoundException;4 ImportJava.io.PrintStream;5 6  Public classha {7      Public Static voidMain (string[] args) {8         Try {  9PrintStream out =System.out; Save the original output streamTenPrintStream PS =NewPrintStream ("./log.txt");//create file output stream One    A System.setout (PS); Setting up a stream with a new file output -             intAge = 11;  -SYSTEM.OUT.PRINTLN ("Age variable is defined successfully, initial value is 11");  theString sex = "female";  -SYSTEM.OUT.PRINTLN ("Age variable successfully defined, initial value is female");  -             //consolidation of 2 variables -String info = "This is a" + Sex + "child, should have" + age + "years old"; +System.out.println ("consolidates two variables as info characters, the result is:" +info); - System.setout (out); Back to the console again . +SYSTEM.OUT.PRINTLN ("The program has finished running, please check the log");  A}Catch(FileNotFoundException e) { at E.printstacktrace ();  -         }   -     } -}

Java Self-study note-Basic syntax 3setOut () method to set a new output stream

Related Article

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.