System.err与System.out的区别

本文介绍了Java中标准输出(System.out)与标准错误输出(System.err)的区别及应用场景,并提供了如何将这两种输出重定向到不同文件的方法,以及如何抑制错误输出的技巧。

System.out leads the output to the standard output stream (normally mapped to the console screen). System.err leads the output to the standard error stream (and, by default to the console, as well). The idea behind having these two is that the standard output should be used for regular program output, and standard error should be used for error messages.

Both the streams can be redirected to different destinations.(这就是所谓的重定向) If it is desired to redirect the output to an output file and error messages to a different log file, than on UNIX it can be done as follows:

 
java MyClass > output.log 2>error.log


This causes the regular output (using System.out) to be stored in output.log and error messages (using System.err) to be stored in error.log.

If you have put error messages in your program, but you don't want to see them, the technique given below can be used to do it:

 
Java MyClass 2> /null


This redirects the System.err messages to /null, so no error messages appear on the screen, but the normal program output can still be seen.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值