What is the System.setErr() function in Java?
Overview
The System.setErr() function is used to reassign the standard error output stream.
Syntax
static void setErr(PrintStream error)
Parameters
error: the new standard error output stream.
Return value
This function does not return a value.
SecurityException: In this exception, thecheckPermission()method does not allow the user to reassign the latest standard error output stream when the security manager exists.
Example
The code below demonstrates how the setErr() function works in Java.
// Load java input output packageimport java.io.*;// Main classpublic class EdPresso {public static void main(String[] args) throws FileNotFoundException {OutputStream outst = new FileOutputStream("file1.txt");PrintStream _printStream = new PrintStream(outst);// set current standarad error output streamSystem.setErr(_printStream);System.out.println("Task completed!");}}