系统类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