Java SOPs redirection

Source: Internet
Author: User

System. out. println (); the smelly statement above prints the specified information to the standard output (screen ). Generally, we can see the printed information on the console. What if we want to persist some information, such as storing it in a file? (Every time you re-run the program, the console information will disappear.) One solution is to redirect the output. [Java] public static void setOut (PrintStream out); the setOut method of the System class is used for redirection. A simple example is as follows: [java] import java. io. file; import java. io. printStream; public class Test {public static void main (String args []) throws Exception {System. setOut (new PrintStream (new File ("g: // loggers.txt"); System. out. println ("hehe"); System. out. println (); System. out. println ("qile") ;}} after running, the console does not have any print information: Enter the g, open loggers.txt: The content is as follows: Next: hehe indicates that it is indeed relocated to the file we specified. The other standard error output streams are similar to the output streams.

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.