Java System类setErr()方法及示例

系统类setErr()方法 (System class setErr() method)

  • setErr() method is available in java.lang package.

    setErr()方法在java.lang包中可用。

  • setErr() method is used to assign again the standard error output stream.

    setErr()方法用于再次分配标准错误输出流。

  • setErr() method is redirected because it does write anything in editor.

    setErr()方法被重定向,因为它确实在编辑器中写入了任何内容。

  • setErr() method writes the output to the proper JTextArea.

    setErr()方法将输出写入适当的JTextArea。

  • setErr() method is a static method, it is accessible with the class name too.

    setErr()方法是静态方法,也可以使用类名进行访问。

  • setErr() method may throw an exception while writing the error to the standard output stream:

    将错误写入标准输出流时, setErr()方法可能会引发异常:

    SecurityException: In this exception checkPermission() method does not allow reassigning of the latest standard error output stream when security manager exists.

    SecurityException:在此异常中,当存在安全管理器时,checkPermission()方法不允许重新分配最新的标准错误输出流。

Syntax:

句法:

    public static void setErr(PrintStream set_err);

Parameter(s):

参数:

  • PrintStream set_err – represents the latest standard error output stream.

    PrintStream set_err –表示最新的标准错误输出流。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回类型为void ,它不返回任何内容。

Example:

例:

// Java program to demonstrate the example of 
// setErr () method of System Class

import java.io.*;

public class SetErrMethod {
    public static void main(String[] args) throws Exception {
        OutputStream outputstream = new FileOutputStream("E://javasource//abc.txt");
        PrintStream printstream = new PrintStream(outputstream);
        System.setErr(printstream);
        System.out.println("File with no error");
    }
}

Output

输出量

E:\Programs>javac SetErrMethod.java
E:\Programs>java SetErrMethod
File with no error


翻译自: https://www.includehelp.com/java/system-class-seterr-method-with-example.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值