The System.setErr()
function is used to reassign the standard error output stream.
static void setErr(PrintStream error)
error
: the new standard error output stream.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.
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!");}}